Check RabbitMQ queue size from client

Viewed 56834

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.

9 Answers

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)

I was able to get the size/depth of queue from python program.

  1. using py_rabbit
    from pyrabbit.api import Client
    cl = Client('10.111.123.54:15672', 'userid', 'password',5)
    depth = cl.get_queue_depth('vhost', 'queue_name')
  1. kombu [a python package usually comes with celery installation]
conn = kombu.Connection('amqp://userid:password@10.111.123.54:5672/vhost')
conn.connect()
client = conn.get_manager()
queues = client.get_queues('vhost')
for queue in queues:
    if queue == queue_name:
    print("tasks waiting in queue:"+str(queue.get("messages_ready")))
    print("tasks currently running:"+str(queue.get("messages_unacknowledged")))

the ip address is just an example.

Edit:

3

I have found a better way to do this . curl appears to be more convenient and faster way to do it


curl -s -i -u $user:$password http://$host_ip_address:15672/api/queues/$vhost_name/$queue_name | sed 's/,/\n/g' | grep '"messages"' | sed 's/"messages"://g'
Related