Queue state and troubleshooting
🎯 Introduction
A task was submitted, but the order still has not completed. Has no consumer received it, or is processing too slow? This article uses three queue counts to narrow the investigation, then payment IDs and program logs to find the cause.
🧰 Inspect three queue counts
Ensure Docker and the course's rabbitmq-course container are running, then execute:
docker exec rabbitmq-course rabbitmqctl list_queues \
name messages_ready messages_unacknowledged consumers
docker exec runs a command inside the specified container. rabbitmqctl list_queues queries queues; the four following fields select output columns. This command only reads state and does not receive or delete messages.
| Output column | Label used here | Meaning |
|---|---|---|
name | Queue name | The queue this row describes |
messages_ready | Ready | Messages waiting for delivery |
messages_unacknowledged | Unacked | Delivered messages for which RabbitMQ has not received an acknowledgement |
consumers | Consumers | Consumers subscribed to this queue |
For example, output might include:
name messages_ready messages_unacknowledged consumers
work.order 1 0 0
This means work.order has one waiting message and no consumers. Consumers counts subscriptions. Each worker in this course has one subscription, so two workers correspond to 2.
Use the course's default connection configuration below and inspect only the work.order row. If the queue does not exist yet, perform the sending step in the next section first. See the rabbitmqctl documentation for field definitions.
🛠 Observe state changes with one task
Reuse send-work.mjs and worker.mjs from consumer acknowledgements. Finish old tasks and stop all workers. Keep prefetch(1) and temporarily change delay(5000) to delay(30000). The thirty-second simulated processing time leaves room to query state.
Send a task in terminal one, then run the queue query above and inspect work.order:
node send-work.mjs P6001
After verifying Ready 1, Unacked 0, and Consumers 0, start the consumer in terminal two:
node worker.mjs
After terminal two prints “Started P6001”, query from terminal one within thirty seconds. Query again after “Completed P6001”:
| Query timing | Ready | Unacked | Consumers |
|---|---|---|---|
| Sent, before starting the worker | 1 | 0 | 0 |
| “Started” printed, still in the thirty-second wait | 0 | 1 | 1 |
| Server received ack, worker still running | 0 | 0 | 1 |
Consumers remains 1 because the program keeps waiting for the next task. Each command shows a snapshot rather than continuous updates; rerun it to observe changes. If you miss processing in progress, use a new ID and observe again without changing acknowledgement code.
These counts describe queue state, not order processing records. Check the business result by payment ID to determine actual completion; Ready and Unacked both being 0 is insufficient.
🔎 Choose what to check from the state
Waiting messages, no consumers
Ready above 0 and Consumers 0 means nobody is currently receiving from this queue. Check whether the worker is still running or reports connection errors. Then verify that it connects to the course's RabbitMQ and subscribes to work.order. Follow installation and connection to investigate connection issues.
Consumers exist, but waiting messages keep growing
Consumers above 0 only shows that subscriptions exist, not that processing is healthy. First look for continuing “Completed” logs for different tasks:
- Tasks keep completing, but Ready grows: new tasks may arrive faster than they finish. Compare sent and completed counts per unit of time before considering more processing capacity.
- No task has completed for a long time: find where the consumer is stuck. If it has reached its prefetch limit, RabbitMQ waits for acknowledgements before delivering more.
Do not add instances solely because a backlog exists. If a slow database or SMS API is the cause, additional requests may worsen it.
Unacked stays above zero
Check whether the current task has exceeded its usual duration, then whether task IDs in the logs are changing. During continuous consumption, old messages are acknowledged while new ones arrive, so Unacked can remain constant without a stall.
If the same task remains unfinished for a long time, inspect business calls that may be waiting, exceptions, and whether ack runs after success. Compare acknowledgement placement with the consumer acknowledgement article if needed.
The queue is empty, but the business result is missing
Use the payment ID to check three sources of evidence:
- The producer's publisher confirms and returns: did the server accept the publication, and was the message returned as unroutable?
- Consumer logs: was this ID received, and did processing end with acknowledgement, rejection, or an error?
- Business records and the relevant dead-letter queue: did the business operation complete, or was the task moved elsewhere?
Inspect resources for the correct business flow: work.order for orders, and notice.tasks plus notice.dead-queue for notifications. work.order has no notification dead-letter route, so do not look for order tasks in notification queues.
❓ Questions and answers
Q1: If I cannot find a queue, does that mean it has no messages?
No. An existing empty queue and a nonexistent queue are different. Verify the queried RabbitMQ instance matches the application's connection and the queue name is correct, then check whether setup succeeded.
Q2: Can queue state identify the payment ID with a problem?
No. These are aggregate counts. Locate a specific task by payment ID in producer logs, consumer logs, and business records.
🧪 Exercise
Finish the previous task and stop the worker. Keep the thirty-second wait and prefetch 1, then send two new tasks:
node send-work.mjs P6011
node send-work.mjs P6012
Query the queue, start one worker, query while the first task waits, and query after both finish. With no old messages, expect Ready/Unacked/Consumers to be 2/0/0, then 1/1/1, then 0/0/1.
Explain why Ready remaining 1 during the first task does not indicate a faulty consumer. Stop the worker after the experiment and restore delay(5000) for the next start.
🎉 You can now use queue state to guide investigation and individual task records to find the cause!
