OpenJMS SimpleConsumer/SimplePublisher persistence querys

A

Alan

I am trying out the OpenJMS client.console package examples provided
in the OpenJMS openjms-0.7.6-rc3 download from
http://openjms.sourceforge.net/.
I'm running SimplePublisher and SimpleConsumer in order to gain some
experience and understanding of JMS in general.

I'm able to run SimpleConsumer and then follow that with running
SimplePublisher to see SimpleConsumer consume the published messages
and that works ok.

But if I run SimplePublisher (with arguments "-topic topic1
-persistent") without having first started SimpleConsumer (with
arguments "-topic topic1 -persistent -ackmode auto") then
SimpleConsumer doesn't seem to see my published messages when it is
restarted.

What have I missed here, I was under the assumption that if I ran
using -persistent (deliveryMode = DeliveryMode.PERSISTENT) then it
does not matter if the Consumer is running or not - they will simple
be consumed next time the Consumer runs.

I'm also unsure what running the Publiher with
"connection.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);" is
supposed to do as I don't see any issues relating to acknoledgements
or lack of.

Can anyone assist?
Many thanks
Alan
 
S

Sudsy

Alan wrote:
But if I run SimplePublisher (with arguments "-topic topic1
-persistent") without having first started SimpleConsumer (with
arguments "-topic topic1 -persistent -ackmode auto") then
SimpleConsumer doesn't seem to see my published messages when it is
restarted.
Can anyone assist?
Many thanks
Alan

When you subscribe to a magazine, do you expect to receive every
single issue since they started publishing? Or do you expect to
get the new issues for the term of your subscription?
It's an appopriate analogy and that's why the terms are used.
 
A

Alan

Thanks, Yes - but I thought persistent mode enabled that; so how can I
ensure that the messages are received regardless of whether my
consumer was downed momentarily for some unexpected reason (does JMS
support this)?

Thanks
Alan
 
S

Sudsy

Alan said:
Thanks, Yes - but I thought persistent mode enabled that; so how can I
ensure that the messages are received regardless of whether my
consumer was downed momentarily for some unexpected reason (does JMS
support this)?

Thanks
Alan

You want a durable subscriber. I hate to waste bandwidth but you don't
show a valid e-mail address. Here is some sample code I was using for
a demo. It's not commented but if you're at all familiar with the
client side of JMS then you should be able to follow along.

class JMSdurableSubscriber extends Frame implements MessageListener {

TopicConnection topicConnection = null;
TextArea output = null;
SimpleDateFormat fmt = new SimpleDateFormat( "HH:mm:ss.SSS" );

public JMSdurableSubscriber( TopicConnectionFactory topicFactory,
Topic topic, int nrows, int ncols, String subscriber ) {
super( "Durable subscriber" );
TopicSession topicSession = null;
TopicSubscriber sub = null;
setSize( 300, 150 );
addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
setVisible( false );
}
} );
try {
topicConnection = topicFactory.createTopicConnection();
topicConnection.setClientID( subscriber );
topicSession = topicConnection.createTopicSession(
false, Session.AUTO_ACKNOWLEDGE );
sub = topicSession.createDurableSubscriber( topic,
subscriber );
sub.setMessageListener( this );
topicConnection.start();
}
catch( JMSException e ) {
e.printStackTrace();
}
output = new TextArea( nrows, ncols );
output.setEditable( false );
add( output, BorderLayout.CENTER );
setVisible( true );
}

public void onMessage( Message msg ) {
if( ! ( msg instanceof TextMessage ) )
return;
TextMessage textMsg = (TextMessage) msg;
try {
output.append( fmt.format( new Date() ) + ": " +
textMsg.getText() + "\r\n" );
}
catch( JMSException e ) {
e.printStackTrace();
}
}

protected void finalize() {
try {
if( topicConnection != null )
topicConnection.close();
}
catch( Exception e ) {
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top