Getting number of messages in a RabbitMQ queue

following the answer of ChillarAnand you can get the value easily. the data is in the object.

import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
            host='localhost',
            port=5672,
            credentials=pika.credentials.PlainCredentials('guest', 'guest'),
        )
channel = connection.channel()
print(channel.queue_declare(queue="your_queue", durable=True,  exclusive=False,
                  auto_delete=False).method.message_count)

and you will get the exact message number


Using pika:

import pika

pika_conn_params = pika.ConnectionParameters(
    host='localhost', port=5672,
    credentials=pika.credentials.PlainCredentials('guest', 'guest'),
)
connection = pika.BlockingConnection(pika_conn_params)
channel = connection.channel()
queue = channel.queue_declare(
    queue="your_queue", durable=True,
    exclusive=False, auto_delete=False
)

print(queue.method.message_count)

Using PyRabbit:

from pyrabbit.api import Client
cl = Client('localhost:55672', 'guest', 'guest')
cl.get_messages('example_vhost', 'example_queue')[0]['message_count']

Using HTTP

Syntax:

curl -i -u user:password http://localhost:15672/api/queues/vhost/queue

Example:

curl -i -u guest:guest http://localhost:15672/api/queues/%2f/celery           

Note: Default vhost is / which needs to be escaped as %2f

Using CLI:

$ sudo rabbitmqctl list_queues | grep 'my_queue'