Bootstrap FreeKB - RabbitMQ - Publish Message using the REST API
RabbitMQ - Publish Message 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 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



Comments


Add a Comment


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