Bootstrap FreeKB - RabbitMQ - Display messages in a queue using the REST API
RabbitMQ - Display messages in a queue using the REST API

Updated:   |  RabbitMQ articles

This assumes you have created a RabbitMQ user with the administrator tag.

Refer to the RabbitMQ REST API documentation.

The curl command can be used to make an API connection to RabbitMQ. In this example, the messages in queue001 in the foo virtual host will be retrieved and then requeued.

  • count 10 means that only 10 messages in the queue will be retrieved
  • There are 4 acknolwedgment modes:
    • ack_requeue_true - the messages will be flagged as acknowledged, the messages remain in the queue
    • reject_requeue_true - the messages will be flagged as rejected, the messages remain in the queue
    • ack_requeue_false - the messages will be flagged as acknowledged, the messages will be dropped
    • reject_requeue_false - the messages will be flagged as rejected, the messages will be dropped
  • truncate limits the size of the output returned in case there is a extra large message
curl 
--request POST 
--user john.doe:itsasecret 
--data '{"count":10,"ackmode":"ack_requeue_true","encoding":"auto","truncate":50000}'
--url http://server001:15671/api/queues/foo/queue001/get

 

Use %2f for the default / (forward slash) virtual host.

curl 
--request POST 
--user john.doe:itsasecret 
--data '{"count":10,"ackmode":"ack_requeue_true","encoding":"auto","truncate":50000}'
--url http://server001:15671/api/queues/%2f/queue001/get

 

Something like this should be returned. In this example, there is 1 message in queue001 and the message payload is "Hello World".

Notice that the result is returned as an array, as indicated by the [ ] (bracket) character. For this reason, if you are going to be parsing the output, you will have to loop over the array

[
 {
  "payload_bytes":6
  "redelivered":true
  "exchange":"exchange001"
  "routing_key":"key001"
  "message_count":1
  "properties":{"timestamp":1622715703
  "delivery_mode":2
  "headers":{"timestamp_in_ms":1622715703577}}
  "payload":"Hello World"
  "payload_encoding":"string"
 }
]

 

timestamp is the date and time that the message was placed in the queue, represented in epoch time, which is the number of seconds that have elapsed since January 1st, 1970. Notice in this example that the message has a timestamp of 1622715703. On a Linux system, the following command can be used to convert 1622715703 to a human friendly date and time format.

~]$ echo $(date -d @1622715703)
Thu Jun 3 05:21:43 CDT 2021

 

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 109ce9 in the box below so that we can be sure you are a human.