rabbitmq - 是否可以直接从 命令行 查看RabbitMQ消息内容?

是否可以直接从命令行查看RabbitMQ消息内容?

sudo rabbitmqctl list_queues列出队列。

有没有sudo rabbitmqctl list_queue_messages queue_name之类的命令?

时间:

你应该启用管理插件。


rabbitmq-plugins enable rabbitmq_management

请参见这里:

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

这里是关于管理的细节。

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

最后,完成设置后,你将需要按照以下说明安装和使用Rabbitmqadmin工具,可用于与系统完全交互,http://www.rabbitmq.com/management-cli.html

例如:


rabbitmqadmin get queue=<QueueName> requeue=false

将会给你队列中的第一条消息。

下面是我用来获取队列的命令:

使用Linux的RabbitMQ版本3.1.5 https://www.rabbitmq.com/management-cli.html


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

以下是我的队列:


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 |
+-------+----------+-------------+-----------+---------+------------------------+---------------------+--------+----------+----------------+-------------------------+---------------------+--------+---------+

将一些项目填充到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查看队列中的消息:


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 |
+-------------+----------+---------------+---------------------------------------+---------------+------------------+------------+-------------+

我编写了rabbitmq-dump-queue,它允许将来自agavi队列的消息转发到本地文件并将消息排序。

例子用法(转储队列incoming_1的前50条消息):


rabbitmq-dump-queue -url="amqp://user:password@rabbitmq.example.com:5672/" -queue=incoming_1 -max-messages=50 -output-dir=/tmp

...