[rabbitmq-discuss] How to achieve HA consumers?
johnson
johnson at edocom.cn
Wed Sep 5 14:51:52 BST 2012
Hi Matthias,
Thanks for your reply. I wrote some test code and found a wired problem.
The init code is like
factory = new ConnectionFactory();
connection = factory.newConnection(address);
channel = connection.createChannel();
channel.basicQos(1);
And the receive code is like
QueueingConsumer consumer = new QueueingConsumer(channel);
boolean autoAck = false;
Queue.DeclareOk declare = channel.queueDeclarePassive("LBCQueue");
int consumerCount = declare.getConsumerCount();
if (consumerCount > 0)
return false;
channel.basicConsume("LBCQueue", autoAck, consumer);
First I started the first consumer and didn't publish any message.
Then I started the second consumer and the value of the variable declare is #method<queue.declare-ok>(queue=LBCQueue, message-count=0, consumer-count=1).
So far everything is OK.
Now I publish 1 messge into the queue and restart the second consumer. The value of the variable declare is #method<queue.declare-ok>(queue=LBCQueue, message-count=0, consumer-count=1).
So far everything is still OK.
Then I publish another message into the queue and restart the second consumer again.
This time the value of declare is #method<queue.declare-ok>(queue=LBCQueue, message-count=1, consumer-count=0).
The message-count is correct but the consumer-count is changed from 1 to 0. I don't know why. Is it a bug?
johnson
From: Matthias Radestock
Date: 2012-09-05 15:48
To: johnson
CC: rabbitmq-discuss; Francesco Mazzoli
Subject: Re: [rabbitmq-discuss] How to achieve HA consumers?
Johnson,
On 05/09/12 05:32, johnson wrote:
> The channel.queueDeclarePassive method returns the consumer count of
> the specified channel,
No it doesn't. queue.declarePassive returns the total number of active
consumers of the queue at that point in time. Regardless of what
connection/channel they were created on.
That should be pretty clear from the docs -
http://www.rabbitmq.com/amqp-0-9-1-reference.html#queue.declare-ok.consumer-count
- which make no mention of the count being connection/channel specific.
> So if I start two consumers [...] in two different machines [...] the
> channel.queueDeclarePassive method always return the consumer count
> == 1, not 2.
I am not sure what you are expecting to see here. If you start two
consumers, the count they will see prior to consuming will be 0 or 1.
As mentioned "You'd need to be mindful of races when consumers start
up.", i.e. if both consumers start up near simultaneously then they will
both see a count of 0.
> 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.
A connection represents a point-to-point TCP connection. You can't
"reuse" that from a third point.
Regards,
Matthias.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120905/8ce6f981/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 22572 bytes
Desc: not available
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120905/8ce6f981/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 22628 bytes
Desc: not available
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120905/8ce6f981/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 22474 bytes
Desc: not available
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120905/8ce6f981/attachment-0002.png>
More information about the rabbitmq-discuss
mailing list