[rabbitmq-discuss] checking no of message in queue

Emile Joubert emile at rabbitmq.com
Tue Mar 22 09:43:42 GMT 2011


Hi cheepu,

Op 22/03/2011 09:01, het cheepu geskryf:
>
> Hi
> 	I am checking the number of message in the queue.
> I am using the fillowing code for this.
>
>   channel.exchangeDeclare("exchange", "direct",true);
>   queuemessageSize=channel.queueDeclarePassive("queue").getMessageCount();
>
> I am using the same connection object. but the channel for both task is
> different.
>
> I started two thread( consumer thread to consume msg from queue and a thread
> to check no of message in queue) which are running continuously but I can
> pause and stop the consumer thread.
> I did the following steps:
> 1. Produced 20 message
> 	Result: queue depth is 0 because all the messages are consumed by the
> consumer thread
> 	This is expected result.
> 2. Next I paused the consumer thread. and then again produced 20 message.
> 	Result: queue depth is 0( This is unexpected because there are 20 messages
> in queue) and message is not consumed by the consumer thread( because they
> are paused ).
>
> 3. Next I stopped the consumer:
> 	Result: Now I am getting the no of message in the queue ie 20.
>
> Question:
> 	Why when the consumer is sleeping then my queue size ( ie message in queue)
> is zero?

This could happen if you are using the  QueueingConsumer in auto-ack 
mode, because the the QueueingConsumer will accept messages from the 
broker and store them in memory on the client. You don't say exactly 
what the consumer thread does - if it just dequeues messages from the 
QueueingConsumer then that is a possible explanation for your observations.

You can use the following command before and after each of your 3 steps 
to confirm:

rabbitmqctl list_queues name messages messages_ready messages_unacknowledged


Regards

Emile


More information about the rabbitmq-discuss mailing list