RabbitMQ - Create a policy 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 will make a connection to the RabbitMQ server listening on port 15671 and then create a policy named deadletter.policy.

curl
--request PUT
--user john.doe:itsasecret
--url http://hostname:15671/api/policies/vhost001/deadletter.policy
--header 'content-type: application/json'
--data '{ "pattern": "foo.queue", "apply-to": "queues", "priority": 0, "definition": {"dead-letter-exchange": "deadletter.exchange", "max-length-bytes": 1048576, "overflow": "reject-publish-dlx" } }'
--write-out "%{http_code}"

 

For the / vhost, use %2F

curl
--request PUT
--user john.doe:itsasecret
--url http://hostname:15671/api/policies/%2f/deadletter.policy
--header 'content-type: application/json'
--data '{ "pattern": "foo.queue", "apply-to": "queues", "priority": 0, "definition": {"dead-letter-exchange": "deadletter.exchange", "max-length-bytes": 1048576, "overflow": "reject-publish-dlx" } }'
--write-out "%{http_code}"

 

No output will be returned, regardless if the policy is or is not created. For this reason, the -w or --write-out option is included to get the return code of the curl command.




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 8aab0 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   |