RabbitMQ - Publish Message using the REST API

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

Refer to the RabbitMQ REST API documentation.

The curl command with the --user option can be used to make an API connection to RabbitMQ. In this example, John Doe publishes message "Hello World" to exchange001 with routing key key001.

curl 
--request POST 
--user john.doe:itsasecret 
--data '{"properties":{},"routing_key":"key001","payload":"Hello World","payload_encoding":"string"}'  
http://server001:15671/api/exchanges/%2f/exchange001/publish

 

Or a JSON file can be created. Let's say foo.json contains the following.

{
  "properties":{},
  "routing_key":"key001",
  "payload":"Hello World",
  "payload_encoding":"string"
}

 

Then the following command can be used.

curl 
--request POST 
--user john.doe:itsasecret 
--data @foo.json  
http://server001:15671/api/exchanges/%2f/exchange001/publish

 

If the message is successfully published, something like this should be returned.

{"routed":true}

 

If the message fails to publish, which can occur if the bad routing key is used, something like this should be returned.

{"routed":false}

 




Did you find this article helpful?

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

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





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




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |