[rabbitmq-discuss] Consumer

Emile Joubert emile at rabbitmq.com
Mon Jul 2 14:05:30 BST 2012


Hi,

On 30/06/12 22:16, Yurisleidy Hernández Moya wrote:
> In the Producer I need to know if there are Consumers connected

> 1- to use the method getConsumerCount of the queue.

The other problem with this approach is that you will fail to account
for any clients consuming messages synchronously, using basic.get.

Another option that you may consider is to monitor the queue length
instead of the number of consumers. The assumption is that if the queue
gets too long then there are probably too few or no consumers servicing
that queue.

> 2-  Declaring a queue as passive in the Producer and autodelete in the
> Consumer. Thus, the queue  only exists when the Consumer is connected
> and the queue is destroyed when the Consumer dies.

A possible solution is to publish with the "immediate" flag:

http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.publish.immediate

This will immediately return the messages to the publisher if the
message cannot be routed to a queue with consumers.


-Emile




More information about the rabbitmq-discuss mailing list