Is it possible to view RabbitMQ message contents directly from the command line?
Solution 1
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.
Solution 2
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 |
+-------------+----------+---------------+---------------------------------------+---------------+------------------+------------+-------------+
Solution 3
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:[email protected]:5672/" -queue=incoming_1 -max-messages=50 -output-dir=/tmp
Solution 4
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
If you don't want the messages requeued, just change ackmode
to ack_requeue_false
.
Solution 5
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
Shears
Updated on July 27, 2020Comments
-
Shears almost 4 years
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>
? -
Scherbius.com about 10 yearsThanks, 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 rabbitmq.com/management-cli.html
-
robthewolf about 10 yearsNo, you can download it from the link and make it accessable by putting it somewhere in your path.
-
jonatan over 8 yearsIf you only want to view the message, and not take it out of the queue, you should drop the
requeue=false
bit and just dorabbitmqadmin get queue=<QueueName>
-
Akshay Hazari over 7 yearsIs 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 over 7 yearsI suppose get and requeue=true essentially tells us that the messages are dequeued and displayed and requeued (pushed_back to front).
-
aKiRa over 7 yearsYou should be aware that the requeueing messages sets the redelivery flag, so subsequent consumers will not get an identical message
-
xtreak about 7 yearsLink is broken. Mirror : web.archive.org/web/20160319074032/http://www.mikeobrien.net/… . Nice custom error page BTW :)
-
gstackoverflow over 6 yearsCan I see messages content in web interface?
-
Richlv over 6 yearsAs
rabbitmqadmin
connects to the web-based API, is sudo needed here? -
tread over 4 yearsWhy does
requeue=True
-
Nick Roz over 3 yearsuse
ackmode=ack_requeue_false
to drop messages orackmode=ack_requeue_true
to keep them in queue instead ofrequeue=false
-
Nick Roz over 3 yearsplus one for
ackmode=ack_requeue_true
, there is no more suchrequeue
option as mentioned in other answers -
Klesun over 3 yearsHow to show more messages than just the first one?
-
JeremyCanfield almost 3 yearsJust a quick note. The
requeue
key is nowackmode
as documented here -> cdn.rawgit.com/rabbitmq/rabbitmq-management/v3.7.9/priv/www/api/… -
Ron almost 3 years@Klesun to show specific number of messages use:
count=5