RabbitMQ – Get messages from a queue using the curl

I am trying to get a few messages from a queue using the HTTP API of rabbitmq.

I am following the documentation in here
I have no vhost
configured.

I tried the following curl command:

curl -i -u guest:guest -H "content-type:application/json" -X POST http://127.0.0.1:15672/api/queues/foo/get -d'{"count":5,"requeue":true,"encoding":"auto","truncate":50000}'

RabbitMQ then answers:

HTTP/1.1 405 Method Not Allowed
vary: origin
Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
Date: Thu, 20 Apr 2017 08:03:28 GMT
Content-Length: 66
Allow: HEAD, GET, PUT, DELETE, OPTIONS

{"error":"Method Not Allowed","reason":""Method Not Allowed"n"}

Can you point out my mistake? How can I get these messages?

you are missing the queue name:

curl -i -u guest:guest -H "content-type:application/json" -X POST http://127.0.0.1:15672/api/queues/foo/my_queue/get -d'{"count":5,"requeue":true,"encoding":"auto","truncate":50000}'

where foo
is the virtual host, and my_queue
is the queue name.

as result:

[
   {
      "payload_bytes":4,
      "redelivered":true,
      "exchange":"",
      "routing_key":"my_queue",
      "message_count":5,
      "properties":{
         "delivery_mode":1,
         "headers":{

         }
      },
      "payload":"test",
      "payload_encoding":"string"
   },
   {
      "payload_bytes":4,
      "redelivered":true,
      "exchange":"",
      "routing_key":"my_queue",
      "message_count":4,
      "properties":{
         "delivery_mode":1,
         "headers":{

         }
      },
      "payload":"test",
      "payload_encoding":"string"
   },
   {
      "payload_bytes":4,
      "redelivered":true,
      "exchange":"",
      "routing_key":"my_queue",
      "message_count":3,
      "properties":{
         "delivery_mode":1,
         "headers":{

         }
      },
      "payload":"test",
      "payload_encoding":"string"
   },
   {
      "payload_bytes":4,
      "redelivered":true,
      "exchange":"",
      "routing_key":"my_queue",
      "message_count":2,
      "properties":{
         "delivery_mode":1,
         "headers":{

         }
      },
      "payload":"test",
      "payload_encoding":"string"
   },
   {
      "payload_bytes":4,
      "redelivered":true,
      "exchange":"",
      "routing_key":"my_queue",
      "message_count":1,
      "properties":{
         "delivery_mode":1,
         "headers":{

         }
      },
      "payload":"test",
      "payload_encoding":"string"
   }
]

EDIT

In case you are using the default vhost:

curl -i -u guest:guest -H "content-type:application/json" -X POST http://127.0.0.1:15672/api/queues/%2f/my_queue/get -d'{"count":5,"requeue":true,"encoding":"auto","truncate":50000}'
Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » RabbitMQ – Get messages from a queue using the curl

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录