RabbitMQ - Update 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.

Let's say there is a policy named foo.policy in virtual host vhost001. Here is how you would return the JSON of the policy using the REST API.

Or to list a policy in a virtual host matching a policy name.

--request GET
--user john.doe:itsasecret
--url http://hostname:15671/api/policies/vhost001/foo.policy


If no matches are found, something like this should be returned.

 'reason' => 'Not Found',
 'error' => 'Object Not Found'


On the other hand, if the policy exists, something like this should be returned. Let's say you want to update the max-lenght-bytes value from 10000000 to 50000000.

  'priority' => 0,
  'pattern' => '^foo.queue',
  'vhost' => 'foo',
  'name' => 'deadletter.foo.queue.policy',
  'apply-to' => 'queues',
  'definition' => {
    'dead-letter-exchange' => 'deadletter.foo.queue.exchange',
    'max-length-bytes' => 10000000,
    'dead-letter-routing-key' => '*',
    'overflow' => 'reject-publish-dlx'


Updating the policy is exactly the same as creating the policy. Here is how you would update the policy max-lenght-bytes to 50000000.

--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": 50000000, "overflow": "reject-publish-dlx" } }'
--write-out "%{http_code}"


No output will be returned, regardless if the policy is or is not update. 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 10559 in the box below so that we can be sure you are a human.


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