[rabbitmq-discuss] Behavior of consumers listening to the same queue

Matthew Sackman matthew at lshift.net
Sat Apr 24 13:53:15 BST 2010


Hi Pierre,

I've just realised I answered totally the wrong question, so I'll have
another go!

On Sat, Apr 24, 2010 at 01:56:21AM -0700, Pierre Coquentin wrote:
> I noticed a behavior that surprised me a little. For example, if I
> register two consumers on two different channels on a shared
> connection, listening to the same queue, I realized that the messages
> were processed one by one using round robin strategy, ie the second
> consumer will not process a message until the first consumer has
> finished processing the previous message and so on. I thought the
> messages would be treated as independent if I used different channels.
> Is there no way to ensure that messages are processed in parallel by
> both consumers except by registering them on two different connections
> ? Or am I just missing something ?

Yes, the messages should be treated independently, and should be able to
be processed in parallel (ignore everything I said in my last email
about multiple queues!).

However, most clients are implemented with one "main" thread which pulls
the messages off the socket. If you are getting that thread to do the
processing, then yes, it'll block, and you'll achieve no parallelism.
You really need for that thread to hand off the message to some other
thread so that the main thread can go back and grab the next message off
the socket.

If you're using our Java client then you need to be using the
QueueingConsumer which exists for exactly this purpose, rather than just
filling in the handleDelivery callback yourself. You didn't mention
which client you're using though.

I hope that helps,

Matthew



More information about the rabbitmq-discuss mailing list