MQ Commands Cheatsheet - Kafka & RabbitMQ

Most message queue incidents are chronic rather than dramatic: a consumer that silently stops, a backlog that keeps growing, or a connection count that only ever climbs. The triage order is consistent even though the commands differ per broker. Read the lag or queue depth first, then check how many consumers are registered and what state they are in, so you can tell "nobody is consuming" apart from "consuming too slowly". Then inspect the connection list to see whether the leak lives in the application pool or inside the broker. Kafka, RabbitMQ, RocketMQ and Redis Pub/Sub each report this differently, and Redis Pub/Sub is the odd one out: it has no backlog to inspect and drops messages while a consumer is disconnected, so the diagnostic question changes entirely. Commands are grouped by backlog, connections, cluster inspection and load testing, including throughput and record-count flags for perf tests. Treat a growing backlog as a symptom to be explained rather than a queue to be emptied, and take the message offset as the unit of investigation.

SysOps·32 commands·Last updated 2026-07-21
mqkafkarabbitmqrocketmqBackloglag

Kafka 6

kafka-consumer-groups.sh --bootstrap-server :9092 --list
List all consumer groups
kafka-consumer-groups.sh --describe --group <group>
View a group's lag and partition progress
kafka-topics.sh --describe --topic <topic>
View topic partitions, replicas and leader distribution
kafka-topics.sh --create --topic <t> --partitions 3 --replication-factor 2
Create a topic with given partitions and replication factor
kafka-console-producer.sh --topic <t> --bootstrap-server :9092
Produce messages from the CLI (for debugging)
kafka-console-consumer.sh --topic <t> --from-beginning --group <g>
Consume from the start and join a consumer group

RabbitMQ 6

rabbitmqctl list_queues name messages consumers
View queue backlog and consumer count
rabbitmqctl list_connections name state channels
View connections and channel count (leak check)
rabbitmqctl list_channels pid number
Find which connection holds many channels
rabbitmqctl cluster_status
View cluster nodes and partition state
rabbitmqadmin get queue=<q> count=1 ack=false
Peek at the head message without ack (debugging)
rabbitmqctl list_exchanges name type / list_bindings
View exchanges and bindings

RocketMQ 5

mqadmin consumerProgress -g <group>
View per-queue backlog progress of a consumer group
mqadmin topicList -m
View topic routing and queue distribution
mqadmin clusterList
View broker cluster status and roles
mqadmin brokerConsumeStats -b <addr> -g <group>
View consumption stats per broker
mqadmin queryMsgById -i <msgId>
Query a message by ID to trace losses

Redis Pub/Sub 5

PUBLISH channel "message"
Publish a message to a channel
SUBSCRIBE channel1 channel2
Subscribe to one or more channels
PSUBSCRIBE news.*
Subscribe to channels matching a pattern
PUBSUB CHANNELS *
List currently active channels
PUBSUB NUMSUB channel
View the subscriber count of a channel

General Backlog & Connection Checks 5

kafka-consumer-groups.sh --describe --group <g> --state
Check whether a group is rebalancing
rabbitmqctl node_health_check
Quick node health check (legacy command)
ss -tnp | grep :9092 | wc -l
Count connections to the broker (leak check)
du -sh /var/lib/kafka /var/lib/rabbitmq
Check MQ disk usage (watch water-mark alerts)
journalctl -u kafka --since "10 min ago"
View recent broker logs for OOM or throttling

Performance Testing & Benchmarking 5

kafka-consumer-perf-test.sh --bootstrap-server :9092 --topic <t> --messages 1000
Benchmark consumer throughput
kafka-producer-perf-test.sh --topic <t> --num-records 100000 --throughput -1
Benchmark producer throughput and latency
rabbitmq-perf-test --queue <q> --rate 1000 --producers 5
Official RabbitMQ benchmarking tool
redis-benchmark -h host -t publish,subscribe -n 100000
Redis Pub/Sub performance benchmark
kafka-consumer-groups.sh --describe --group <g> --members --verbose
View consumer-group members and assignments

Command Examples

Read the backlog from the consumer group view: LAG and partition assignment

kafka-consumer-groups.sh --bootstrap-server :9092 --list kafka-consumer-groups.sh --describe --group <group> --members --verbose

A zero-LAG partition shows the topic is fully covered, and all the backlog sits on one consumer. Adding consumer instances will not spread the work because the partition count caps parallelism — the real fix is usually more partitions first, then more consumers.

Output

order-consumer
inventory-consumer

GROUP           TOPIC         PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG  CONSUMER-ID
order-consumer  orders        0          48102           48310           208  order-consumer-1-9f2c
order-consumer  orders        1          47880           48311           431  order-consumer-1-9f2c
order-consumer  orders        2          48311           48311             0

Consumer group 'order-consumer' has 1 active consumer.

One RabbitMQ command separates "nobody consumes" from "consumption is slow"

rabbitmqctl list_queues name messages consumers

orders has a high count with zero consumers, which is a registration or connectivity problem; emails has three consumers and a small backlog, which is healthy throughput. Because the two shapes call for entirely different responses, separating them matters more than reaching for a queue purge.

Output

Listing queues for vhost / ...
name    messages  consumers
orders  15230     0
emails  18        3

Trace by message ID: confirm the message actually reached the broker

mqadmin queryMsgById -i <msgId>

If it is found, production succeeded and the problem is on the consumption side; if not, the producer never sent it or it has already been reclaimed. This establishes the boundary of responsibility before you start reading logs on either side.

Output

Topic: ORDER_CREATED | Queue: BROKER_MSG_QUEUE_ID_0 | Offset: 48310 | Size: 214 bytes | QueueOffset: 15230

Inspect topic structure and cluster roles before load testing

kafka-topics.sh --describe --topic <t> mqadmin clusterList

An Isr shorter than the replica list means replicas are out of sync, and throughput measured in that state is not representative — restore replication first. Partition count likewise caps the concurrency any load test can reach.

Output

Topic: orders    TopicId: 7Lk-9pQ2x    PartitionCount: 3    ReplicationFactor: 2    Configs: 
Topic: orders    Partition: 0    Leader: 2    Replicas: 2,1    Isr: 2,1
Topic: orders    Partition: 1    Leader: 1    Replicas: 1,2    Isr: 1
Topic: orders    Partition: 2    Leader: 2    Replicas: 2,1    Isr: 2,1

Common Pitfalls

  • A backlog is a symptom, not a cause. Use the consumer group view and queue fields to tell apart too few consumers, slow consumption and failed routing — purging the queue only destroys the evidence you need.
  • Confirm durability settings before restarting or resetting a broker. Messages that never reached disk are simply gone and cannot be recovered from the client side afterwards.
  • kafka-console-producer.sh writes to a real topic. Double-check the topic name and that it is isolated from production traffic, or you will inject junk into a live stream.
  • rabbitmqadmin get removes the message from the head of the queue even with ack=false, so repeated sampling perturbs the original delivery order.
  • kafka-producer-perf-test.sh --throughput -1 and an unthrottled rabbitmq-perf-test can saturate disk and network within seconds. Confirm you are on an isolated environment before running either.

Tips

  • For message backlog, first check lag and consumer count to tell slow consumers from too few — don't just purge the queue.
  • When hunting connection leaks, check both list_connections and the app's connection-pool config; looking at one side alone misleads.
  • Before restarting a broker, confirm messages are persisted; unflushed messages are lost.
  • In Kafka perf tests, --throughput -1 means uncapped; combine with --num-records for peak throughput.
  • Redis Pub/Sub is not persistent; messages during a disconnect are lost. Use Stream for reliable delivery.
  • When a RabbitMQ queue backs up, check the consumers column first; 0 means consumers aren't registered or have dropped.

FAQ

The LAG column keeps climbing in Kafka. Is consumption too slow or are there too few consumers?

First use kafka-consumer-groups.sh --describe --group <group> to see whether LAG grows steadily or merely spikes: steady growth means the consumption rate sits below the production rate and the gap is widening, whereas a spike that returns to baseline is transient noise. Then pair it with --members --verbose to see group membership and partition assignment. If idle partitions exist you have too few consumers to cover the topic; if every partition is assigned and LAG still climbs, individual consumers are simply too slow and adding machines will not help.

A RabbitMQ queue holds messages but nothing consumes them. Which fields first?

Run rabbitmqctl list_queues name messages consumers to get everything in one shot. Messages present with consumers at 0 means messages arrive but no consumer is registered or has disconnected — check the application side, whether it is running and pointed at the same vhost. If consumers is above 0 and nothing is still consumed, the messages are not being routed: rabbitmqctl list_exchanges name type and list_bindings then reveal the exchange types and bindings, and the usual culprit is an exchange declared with the binding forgotten.

How do I tell whether a connection leak is on the application side or the broker side?

Look at both. On the broker, rabbitmqctl list_connections name state channels gives connection and channel counts, and list_channels pid number identifies which single connection is holding many channels — far more channels than the workload needs usually means connections are not being reused. On the host, ss -tnp | grep :9092 | wc -l counts connections reaching the broker, which you compare against the pool size the application is configured with. Broker-side counts that look sane while the host-side count keeps climbing point at a pool that never releases.

Why is a "lost message" in Redis Pub/Sub impossible to investigate?

Because Pub/Sub has neither persistence nor an offset. A client that disconnects while subscribed loses everything published in the gap, and PUBSUB CHANNELS * only lists currently active channels while PUBSUB NUMSUB channel only counts present subscribers — there is no observation point that can tell you what you missed. So the investigation is not about finding the message but about confirming the consumer is present and deciding whether loss is acceptable. If it is not, move to a solution with consumer groups rather than trying to make Pub/Sub reliable.

What does --throughput -1 mean in the Kafka performance test?

It means no rate limit: kafka-producer-perf-test.sh pushes as fast as the system allows, which measures the throughput ceiling rather than steady-state latency. --num-records sets the total record count. If you care about tail latency in production, do not run unthrottled — set a rate near your real peak instead, or the measured ceiling means nothing operationally. Before any of it, confirm partition count with kafka-topics.sh --describe --topic <topic>, because a low partition count makes you hit a per-partition bottleneck before a broker one.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us