Check RabbitMQ queue size from client

Pablote picture Pablote · Jun 24, 2009 · Viewed 44.3k times · Source

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.

Answer

mmalone picture mmalone · Mar 4, 2010

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)