RabbitMQ - Get messages from a queue using curl

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}'

Note that the syntax seems to have changed in more recent releases (and the HTTP API documentation seems to be lagging behind) and instead of the requeue option the ack_mode option needs to be set, e.g. "ack_mode"="ack_requeue_true"

So the example above for current RabbitMQ versions would be:

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

I managed to solve the problem. The key:

I have no vhost configured.

RabbitMQ uses the "/" notation for the default VHOST.

enter image description here

"/" is translated to %2F in HTTP...

So the correct call is:

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