RabbitMQ
Queue Size
Client-side
Message Queuing
Programming

Check RabbitMQ queue size (message count) from a client

Codemia Knowledge Hub ·

From client code, declare the queue in passive mode and read the message count from the reply. Outside your application, rabbitmqctl list_queues name messages or the management plugin's web UI and HTTP API give the same number.

Which queue metrics RabbitMQ reports

  • Queue size (message count): Total number of messages currently in the queue.
  • Ready messages: Messages ready to be delivered to consumers.
  • Unacknowledged messages: Messages delivered to a consumer but not yet acknowledged.

Passive queue_declare in a client library

Most languages have a RabbitMQ client library (for example pika for Python or rabbitmq-c for C). With Pika:

python
1import pika
2
3connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
4channel = connection.channel()
5queue = channel.queue_declare(queue='test', passive=True)
6print(queue.method.message_count)
7connection.close()

The script connects to RabbitMQ, declares the queue in passive mode (so it is not created if it does not exist) and prints the number of messages.

rabbitmqctl on the command line

RabbitMQ ships with rabbitmqctl, which inspects the server state, including queue sizes:

bash
rabbitmqctl list_queues name messages

This lists each queue with its message count.

Management plugin: web UI and HTTP API

The management plugin adds a web UI and an HTTP API for monitoring and managing RabbitMQ. Once it is enabled, the web interface is usually at http://<host>:15672/ and shows every queue with its metrics.

To fetch the data programmatically, call the HTTP API:

bash
curl -u user:password http://<host>:15672/api/queues/%2F/<queue_name>

This returns JSON about the queue, including its message count.

Comparing the methods

MethodAdvantagesDisadvantages
Web Interface (Management Plugin)Easy to use, visual interface, no coding requiredRequires web access, less automation
HTTP API (Management Plugin)Automatable, can integrate with systemsRequires enabling HTTP API, programmatic access
rabbitmqctl Command Line InterfaceQuick, does not require programmingLess flexible, limited to machine with access
Client Library (e.g., Pika for Python)Full control, can be integrated into applicationsRequires programming, more complex setup
  • Security: Secure access to RabbitMQ with TLS/SSL connections and user permissions.
  • Performance: Monitoring itself affects RabbitMQ's performance, so keep it light.
  • Alerting and automation: Set up alerts on queue sizes and automate responses to them.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design