JMS queue with multiple consumers

Viewed 18255

I have a JBoss-6 server with HornetQ and a single queue:

<queue name="my.queue">  
    <entry name="/queue/test"/>  
</queue>

There a different consumers (on different machines) connected to this queue, but only a single consumer is active at a time. If I shut down this consumer, the messages are immediately processed by one of the other consumers.

Since my messages have some time consuming processing, I want multiple consumer process their unique messages concurrently.

I remember a similar in earlier versions of JBoss where this setup worked without problems. Here in Jboss-6 the messaging system is working well -- except of the issue described above. This question is similar to Are multiple client consumers possible in hornetq?, but the scenario is not similar to mine.

Update 1: If I close (STRG+C) one consumer there is a short timeout (until the server recognized the lost consumer) until the next consumer gets the message.

Update 2: Code Snippet

VoidListener ml = new VoidListener();
QueueConnectionFactory qcf = (QueueConnectionFactory)
                             ctx.lookup("ConnectionFactory");
QueueConnection conn = qcf.createQueueConnection();
Queue queue = (Queue) ctx.lookup(queueName);
QueueSession session = conn.createQueueSession(false,
                                               QueueSession.AUTO_ACKNOWLEDGE);

QueueReceiver recv = session.createReceiver(queue,"");
recv.setMessageListener(ml);
conn.start();

And the MessageListerner:

public class OlVoidListener implements MessageListener
{
  public void onMessage(Message msg)
  {
    counter++;
    logger.debug("Message ("+counter+") received");
    try {Thread.sleep(15*1000);} catch (InterruptedException e) {}
  }
}
2 Answers
Related