RabbitMQ
Message Queue
Programming
Message Count
Data Management

RabbitMQ: get the number of messages in a queue

Codemia Knowledge Hub ·

On the broker host, run rabbitmqctl list_queues name messages messages_ready messages_unacknowledged. The messages column is the total in each queue, which is usually what "total enqueued" means. RabbitMQ reports ready and unacknowledged messages separately, and that split matters when you diagnose a backlog.

Counting with rabbitmqctl

bash
rabbitmqctl list_queues name messages messages_ready messages_unacknowledged

The columns are:

  • messages: total messages visible to the queue
  • messages_ready: messages waiting to be delivered
  • messages_unacknowledged: messages delivered to consumers but not yet acknowledged

For a single queue:

bash
rabbitmqctl list_queues name messages | grep '^task_queue'

This is often enough for operational checks and debugging.

Reading the breakdown

messages includes both ready and unacknowledged messages, so it does not mean "messages waiting to be processed". A queue showing messages = 5000 is not a diagnosis on its own:

  • A high messages_ready means consumers are not keeping up.
  • A high messages_unacknowledged means consumers may be slow, stuck or not acknowledging correctly.

Counting through the management HTTP API

With the management plugin enabled, the HTTP API is often the easiest option for scripts and monitoring. This returns JSON for all queues:

bash
curl -u guest:guest http://localhost:15672/api/queues

For one queue, add its virtual host and name:

bash
curl -u guest:guest http://localhost:15672/api/queues/%2F/task_queue

%2F is the URL-encoded default virtual host /. The fields to read are messages, messages_ready and messages_unacknowledged. Make sure you query the right virtual host: the same queue name can exist in several of them.

Counting from application code

Many client libraries can declare a queue passively and read the count from the result. In Python with Pika:

python
1import pika
2
3connection = pika.BlockingConnection(pika.ConnectionParameters("localhost"))
4channel = connection.channel()
5
6result = channel.queue_declare(queue="task_queue", passive=True)
7print(result.method.message_count)
8
9connection.close()

A passive declare asks RabbitMQ about the queue without changing its definition, which suits diagnostics, health checks and admin tooling. Keep it out of hot application paths, where it adds unnecessary broker calls; poll deliberately for monitoring instead.

Totaling all queues

To get the backlog across every queue, sum the messages column:

bash
rabbitmqctl list_queues messages --quiet | awk '{sum += $1} END {print sum}'

A single global number can hide one failing queue among healthy ones. Track both per-queue depth (for diagnosis) and aggregate depth (for capacity trends).

Watching counts over time

For ongoing operations, the management UI, Prometheus exporters and dashboards are better than one-off CLI checks. Knowing whether a queue is rising, draining or stuck is usually more useful than a single snapshot.


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