138

Is it possible to view RabbitMQ message contents directly from the command line?

sudo rabbitmqctl list_queues lists the queues.

Is there any command like sudo rabbitmqctl list_queue_messages <queue_name>?

Pang
  • 9,564
  • 146
  • 81
  • 122
Shears
  • 1,539
  • 2
  • 11
  • 6
  • 1
    About installing rabbitmqadmin on linux https://stackoverflow.com/questions/36336071/install-rabbitmqadmin-on-linux/ – Alexey Shrub May 24 '19 at 13:51

6 Answers6

129

You should enable the management plugin.

rabbitmq-plugins enable rabbitmq_management

See here:

http://www.rabbitmq.com/plugins.html

And here for the specifics of management.

http://www.rabbitmq.com/management.html

Finally once set up you will need to follow the instructions below to install and use the rabbitmqadmin tool. Which can be used to fully interact with the system. http://www.rabbitmq.com/management-cli.html

For example:

rabbitmqadmin get queue=<QueueName> requeue=false

will give you the first message off the queue.

pix0r
  • 31,139
  • 18
  • 86
  • 102
robthewolf
  • 7,343
  • 3
  • 29
  • 29
  • 1
    Thanks, works for me! this may contribute: by default rabbitmqadmin can't be called from everywhere. Its located in /var/lib/rabbitmq/mnesia/rabbit@NODENAME-plugins-expand/rabbitmq_management-3.1.3/priv/www/cli. One needs to fix permissions for it (chmod 755 rabbitmqadmin) and maybe copy it to /usr/local/bin , see http://www.rabbitmq.com/management-cli.html – Scherbius.com Feb 07 '14 at 15:47
  • No, you can download it from the link and make it accessable by putting it somewhere in your path. – robthewolf Feb 09 '14 at 06:15
  • 17
    If you only want to view the message, and not take it out of the queue, you should drop the ``requeue=false`` bit and just do ``rabbitmqadmin get queue=`` – jonatan Oct 29 '15 at 18:21
  • 2
    You should be aware that the requeueing messages sets the redelivery flag, so subsequent consumers will not get an identical message – aKiRa Jan 04 '17 at 12:03
  • 1
    Can I see messages content in web interface? – gstackoverflow Aug 15 '17 at 12:21
  • 1
    use `ackmode=ack_requeue_false` to drop messages or `ackmode=ack_requeue_true` to keep them in queue instead of `requeue=false` – Nick Roz Aug 28 '20 at 11:13
  • How to show more messages than just the first one? – Klesun Jan 28 '21 at 13:11
  • @Klesun to show specific number of messages use: `count=5` – Ron Jul 04 '21 at 15:26
55

Here are the commands I use to get the contents of the queue:

RabbitMQ version 3.1.5 on Fedora linux using https://www.rabbitmq.com/management-cli.html

Here are my exchanges:

eric@dev ~ $ sudo python rabbitmqadmin list exchanges
+-------+--------------------+---------+-------------+---------+----------+
| vhost |        name        |  type   | auto_delete | durable | internal |
+-------+--------------------+---------+-------------+---------+----------+
| /     |                    | direct  | False       | True    | False    |
| /     | kowalski           | topic   | False       | True    | False    |
+-------+--------------------+---------+-------------+---------+----------+

Here is my queue:

eric@dev ~ $ sudo python rabbitmqadmin list queues
+-------+----------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+
| vhost |   name   | auto_delete | consumers | durable | exclusive_consumer_tag |     idle_since      | memory | messages | messages_ready | messages_unacknowledged |        node         | policy | status  |
+-------+----------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+
| /     | myqueue  | False       | 0         | True    |                        | 2014-09-10 13:32:18 | 13760  | 0        | 0              | 0                       |rabbit@ip-11-1-52-125|        | running |
+-------+----------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+

Cram some items into myqueue:

curl -i -u guest:guest http://localhost:15672/api/exchanges/%2f/kowalski/publish -d '{"properties":{},"routing_key":"abcxyz","payload":"foobar","payload_encoding":"string"}'
HTTP/1.1 200 OK
Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
Date: Wed, 10 Sep 2014 17:46:59 GMT
content-type: application/json
Content-Length: 15
Cache-Control: no-cache

{"routed":true}

RabbitMQ see messages in queue:

eric@dev ~ $ sudo python rabbitmqadmin get queue=myqueue requeue=true count=10
+-------------+----------+---------------+---------------------------------------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count |                        payload        | payload_bytes | payload_encoding | properties | redelivered |
+-------------+----------+---------------+---------------------------------------+---------------+------------------+------------+-------------+
| abcxyz      | kowalski | 10            | foobar                                | 6             | string           |            | True        |
| abcxyz      | kowalski | 9             | {'testdata':'test'}                   | 19            | string           |            | True        |
| abcxyz      | kowalski | 8             | {'mykey':'myvalue'}                   | 19            | string           |            | True        |
| abcxyz      | kowalski | 7             | {'mykey':'myvalue'}                   | 19            | string           |            | True        |
+-------------+----------+---------------+---------------------------------------+---------------+------------------+------------+-------------+
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
  • 2
    Is the command `sudo python rabbitmqadmin get queue=myqueue requeue=true count=10` to see messages or to dequeue the messages from the end and then requeue them to the front. Is there a way to just see the messages instead of dequeing them. – Akshay Hazari Aug 09 '16 at 12:10
  • I suppose get and requeue=true essentially tells us that the messages are dequeued and displayed and requeued (pushed_back to front). – Akshay Hazari Aug 09 '16 at 12:12
  • 1
    As `rabbitmqadmin` connects to the web-based API, is sudo needed here? – Richlv Oct 30 '17 at 05:58
  • 1
    Why does `requeue=True` – tread Oct 17 '19 at 07:00
23

I wrote rabbitmq-dump-queue which allows dumping messages from a RabbitMQ queue to local files and requeuing the messages in their original order.

Example usage (to dump the first 50 messages of queue incoming_1):

rabbitmq-dump-queue -url="amqp://user:password@rabbitmq.example.com:5672/" -queue=incoming_1 -max-messages=50 -output-dir=/tmp
dubek
  • 11,447
  • 5
  • 30
  • 23
  • 1
    Dubek your tool saved me a lot of time and effort, and it works like a charm, I got saved 54k in messages from a RMQ queue which I was unable to get from the UI. – wpp Dec 21 '22 at 16:08
16

If you want multiple messages from a queue, say 10 messages, the command to use is:

rabbitmqadmin get queue=<QueueName> ackmode=ack_requeue_true count=10

This is how it looks on front interface avalable on http://localhost:15672 :

enter image description here

If you don't want the messages requeued, just change ackmode to ack_requeue_false.

Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
Joshua T
  • 656
  • 8
  • 15
  • 3
    plus one for `ackmode=ack_requeue_true`, there is no more such `requeue` option as mentioned in other answers – Nick Roz Aug 28 '20 at 11:14
11

you can use RabbitMQ API to get count or messages :

/api/queues/vhost/name/get

Get messages from a queue. (This is not an HTTP GET as it will alter the state of the queue.) You should post a body looking like:

{"count":5,"requeue":true,"encoding":"auto","truncate":50000}

count controls the maximum number of messages to get. You may get fewer messages than this if the queue cannot immediately provide them.

requeue determines whether the messages will be removed from the queue. If requeue is true they will be requeued - but their redelivered flag will be set. encoding must be either "auto" (in which case the payload will be returned as a string if it is valid UTF-8, and base64 encoded otherwise), or "base64" (in which case the payload will always be base64 encoded). If truncate is present it will truncate the message payload if it is larger than the size given (in bytes). truncate is optional; all other keys are mandatory.

Please note that the publish / get paths in the HTTP API are intended for injecting test messages, diagnostics etc - they do not implement reliable delivery and so should be treated as a sysadmin's tool rather than a general API for messaging.

http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_1_3/priv/www/api/index.html

Jesse Yan
  • 199
  • 1
  • 4
  • Just a quick note. The `requeue` key is now `ackmode` as documented here -> https://cdn.rawgit.com/rabbitmq/rabbitmq-management/v3.7.9/priv/www/api/index.html – JeremyCanfield Jun 10 '21 at 10:11
5

a bit late to this, but yes rabbitmq has a build in tracer that allows you to see the incomming messages in a log. When enabled, you can just tail -f /var/tmp/rabbitmq-tracing/.log (on mac) to watch the messages.

the detailed discription is here http://www.mikeobrien.net/blog/tracing-rabbitmq-messages

drhagen
  • 8,331
  • 8
  • 53
  • 82
domi
  • 2,167
  • 1
  • 28
  • 45
  • 5
    Link is broken. Mirror : http://web.archive.org/web/20160319074032/http://www.mikeobrien.net/blog/tracing-rabbitmq-messages . Nice custom error page BTW :) – xtreak Mar 08 '17 at 06:12