[rabbitmq-discuss] How to achieve HA consumers?

johnson johnson at edocom.cn
Wed Sep 5 05:32:05 BST 2012


Thanks Matthias and Francesco.

Your second approach is prefect and should work fine. I will choose this approach.

However, I have little concern about the first approach. The channel.queueDeclarePassive method returns the consumer count of the specified channel, but the total number of the consumers connected to the rabbitmq server. So if I start two consumers using the following code in two different machines, i.e., two different JVMs, each consumer needs to create a new connection and a new channel. In this way, the channel.queueDeclarePassive method always return the consumer count == 1, not 2. 

  factory = new ConnectionFactory();
  connection = factory.newConnection(address);
  channel = connection.createChannel();

I also try to find a API that can retrieve the existing connection or channel. Then the second consumer can reuse the connection or channel the first consumer created. But it seems no such APIs.




johnson

From: Matthias Radestock
Date: 2012-08-31 19:39
To: Discussions about RabbitMQ
CC: Francesco Mazzoli; johnson
Subject: Re: [rabbitmq-discuss] How to achieve HA consumers?
On 31/08/12 12:27, Francesco Mazzoli wrote:
>    * The second consumer polls the first in some way and starts consuming when it
>      realises the first consumer is dead.  This is simple and should serve you
>      right, but it's not that nice performance wise.

A passive queue.declare, which returns the consumer_count could 
accomplish this. You'd need to be mindful of races when consumers start up.

>    * You create a second queue that we'll call "token queue", and you publish one
>      dummy message in it, with acks enabled.  Then, a consumer wishing to consume
>      from your queue, will:
>
>        - Consume from the token queue

More specifically, start consuming and wait for the token message to 
arrive. And then...

>        - Start consuming from the actual queue
>        - When shutting down, publish a dummy message to the token queue

No need for the last step (and in fact it will lead to token 
duplication). Simply leave the message unack'ed and let the automatic 
requeue on connection closure/failure take care of the rest.

Matthias.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120905/33efe343/attachment.htm>


More information about the rabbitmq-discuss mailing list