Yurisleidy Hernández Moya | 30 Jun 2012 23:16
Picon
Favicon

Consumer

In the Producer I need to know if there are Consumers connected to the queue or not, to know if the messages could be processed in a medium or long term.

I use the java client. To solve my problem I thought in:

1- to use the method getConsumerCount of the queue.

AMQP.Queue.DeclareOk my_queue = queueDeclare("name_queue", false, false, false, null);
int cont = my_queue.getConsumerCount();

but, the consumer is disconnected of the queue when it is processing the message. For this reason, the Producer fails to recognize that there are Consumers for to work when really yes exist.

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.

In el Consumer: channel.queueDeclare("nam_queue", false, false, true, null);

but the queue is also destroyed when the Consumer reads every message.

Any idea for to know in the Producer if there are Consumers connected?

Thanks in advance.
Yuri.


<div>
<div>In the Producer I need to know if there are Consumers connected to the queue or not, to know if the messages could be processed in a medium or long term.<br><br>I use the java client. To solve my problem I thought in:<br><br>1- to use the method getConsumerCount of the queue.<br><br>AMQP.Queue.DeclareOk my_queue = queueDeclare("name_queue", false, false, false, null);<br><span>int cont = my_queue.getConsumerCount();</span><br><br>but, the consumer is disconnected of the queue when it is processing the message. For this reason, the Producer fails to recognize that there are Consumers for to work when really yes exist.<br><br>2-&nbsp; Declaring a queue as <span>passive</span> in the Producer and <span>autodelete</span> in the Consumer. Thus, the queue&nbsp; only exists when the Consumer is connected and the queue is destroyed when the Consumer dies.<br><br>In el Consumer: <span>channel.queueDeclare("nam_queue", false, false, true, null);</span><br><br>but the queue is also destroyed when the Consumer reads every message.<br><br>Any idea for to know in the Producer if there are Consumers connected?<br><br>Thanks in advance.<br>Yuri.<br>
</div>
<br><a href="http://www.uci.cu/">
</a><br>
</div>
Emile Joubert | 2 Jul 2012 15:05
Favicon

Re: Consumer

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

Emile Joubert | 2 Jul 2012 17:30
Favicon

Re: Consumer

Hi,

On 02/07/12 16:14, Yurisleidy Hernández Moya wrote:
> The client behave like consumers when they consume message with
> basicGet? I tried with two clients. A Client consumes messages from
> the queue and another Client account the number of consumers. The
> number of consumers was always zero. This case is that you tell me?

Clients can obtain messages using basic.get or basic.consume. Only in
the case of basic.consume will they be registered as consumers. If
clients use basic.get then they will typically poll the broker periodically.

> Using the immediate flag, How I can do to receive in the Client the
> undeliverable message?

Register a return handler. See
http://www.rabbitmq.com/amqp-0-9-1-quickref.html#basic.return
The exact details of how to do this will depend on your AMQP client.

-Emile


Gmane