Does anyone know if there\'s a way to check the number of messages in a RabbitMQ queue from a client application?
I\'m using the .NET client library.
If you want to do this in .NET, check which version of the client library you are using.
I'm using the 2.2.0 version and I had to use BasicGet(queue, noAck).
In this version of the library, QueueDeclare() only returns a string containing the queue name.
BasicGetResult result = channel.BasicGet("QueueName", false);
uint count = result != null ? result.MessageCount : 0;
I know from the 2.6.1 version, QueueDeclare() returns an object of type QueueDeclareOk.
QueueDeclareOk result = channel.QueueDeclare();
uint count = result.MessageCount;
Alternatively, you can call from the command line:
<InstallPathToRabbitMq>\sbin\rabbitmqctl.bat list_queues
And you see the following output:
Listing queues...
QueueName 1
...done.
You can use the IModel's MessageCount method, documented here
http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v3.6.4/rabbitmq-dotnet-client-3.6.4-client-htmldoc/html/type-RabbitMQ.Client.IModel.html#method-M:RabbitMQ.Client.IModel.MessageCount(System.String)
edit: I know this is a very old post, but it is the first google response, and I hope it will help people looking for this answer in the future.
You can actually retrieve this via the client.
When you perform a queue_declare
operation, RabbitMQ returns a tuple with three values: (<queue name>, <message count>, <consumer count>)
. The passive
argument to queue_declare
allows you to check whether a queue exists without modifying the server state, so you can use queue_declare
with the passive
option to check the queue length.
Not sure about .NET, but in Python, it looks something like this:
name, jobs, consumers = chan.queue_declare(queue=queuename, passive=True)