Hi,

I'm not sure if this is what you are looking for:
http://java.sun.com/j2ee/1.4/docs/api/javax/jms/MessageConsumer.html#setMessageListener(javax.jms.MessageListener)
http://java.sun.com/j2ee/1.4/docs/api/javax/jms/MessageListener.html

You can set a message listener for each consumer, and the onMessage method for each consumer will be called whenever a message arrives that is targeted to that consumer. If you download the source code of ActiveMQ, we have a lot of unit test cases that provides a lot of example on using JMS and ActiveMQ.

Welcome to the messaging community, btw. :)

Regards,
Adrian Co

Benjamin Wootton wrote:

** Apologies if this came through yesterday.  I sent it once but don't
think it left my outbox! **

I'm new to messaging so forgive me if this is a silly question.

I would like a number of in-process consumers subscribing to different
topics.

Whenever one of these topics ticks, I would like to callback to a Java
method.

What is the right idiom for doing this?  Something like the following is
fine in the scenario where we only have a single consumer:

while ( ( message = consumer.receive( 10000 )  ) != null )
{ processMessage( message );
}

But clearly isn't what we need where we have multiple consumers.

I've considered placing each consumer in it's own thread, but I'd like
the callback to be called in a deterministic order (ie the same order
that the message arrives in.)  The semantics of the avaialble receive
methods also don't seem to fit with doing this.

               new Thread()
{ public void run() { try
                       {
                           Message message;
                           while ( ( message = consumer.receive(
                           1000000 )  ) != null )
{ processMessage( message );
                           }
                       }
                       catch( Exception exception )
                       {
                           exception.printStackTrace();
                       }
                   }
}.start();
Is there any example code around for this?

Thanks in advance
Ben

Reply via email to