Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMS queue with multiple consumers

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) {}
  }
}
like image 821
Thor Avatar asked Aug 10 '11 09:08

Thor


People also ask

Can a JMS queue have multiple consumers?

You can certainly have multiple consumers. As many as you want/need actually. A queue makes sure that every message is processed once and only once by a consumer. A topic is used that one message needs to be processed to multiple subscribers.

Is it possible that multiple consumers of a RabbitMQ queue get the same message?

RabbitMQ has a plugin for consistent hash exchange. Using that exchange, and one consumer per queue, we can achieve message order with multiple consumers. The hash exchange distributes routing keys among queues, instead of messages among queues. This means all messages with the same routing key will go the same queue.

Can RabbitMQ have multiple consumers?

RabbitMQ is an open source multi-protocol messaging broker. The task is to process the messages in queue “faster”, so the main idea is that we need to subscribe to it using several consumers.

What is number of consumers in ActiveMQ?

You can write two consumers—a heads consumer and a tails consumer—that subscribe to that topic but that only receive messages with their selected value of the coin property.


1 Answers

With multiple consumers on a queue, messages are load balanced between the consumers.

As you have some time consuming the message, you should disable buffering by setting consumer-window-size.

On hornetQ there's an example on the distribution, about how to disable client buffering and give a better support for slow consumers. (a slow consumer is a consumer that will have some time processing the message)

message systems will pre-fetch/read-ahead messages to the client buffer to speed up processing and avoid network latency. This is not an issue if you have fast processing queues and a single consumer.

JBoss Messaging offered the slow-consumer option at the connection factory and hornetq offers the consumer window size.

Most Message systems will provide you a way to enable or disable client pre-fetching.

like image 137
Clebert Suconic Avatar answered Sep 20 '22 12:09

Clebert Suconic