RabbitMQ - Delete messages using the REST API

by
Jeremy Canfield |
Updated: February 23 2022
| 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 purge the messages from queue001 from the RabbitMQ server001 listening on port 15671.
curl -X DELETE --user john.doe:itsasecret http://server001:15671/api/queues/%2f/queue001/contents
If the purge is successfully, no output will be returned. --write-out "%{http_code}" can be included to return the http code. The return code should be 204 (success) or 405 (failed).
~]# curl -X DELETE --write-out "%{http_code}" --user john.doe:itsasecret http://server001:15671/api/queues/%2f/queue001/contents
204
Or, on a Linux system, the $? command can be used to determine if the curl command was or was not successful. $? will return 0 if the purge was successful, or 1 if the purge failed.
~]# echo $?
0
Did you find this article helpful?
If so, consider buying me a coffee over at