
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, foo.queue in virtual host vhost001 will be deleted.
curl
--request DELETE
--user john.doe:itsasecret
--url http://server001:15671/api/queues/vhost001/foo.queue
For the / vhost, use %2F.
curl
--request DELETE
--user john.doe:itsasecret
--url http://server001:15671/api/queues/%2f/foo.queue
If the delete 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/foo.queue
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 delete was successful, or 1 if the delete failed.
~]# echo $?
0
The --if-empty option can be included to only delete the queue if it contains 0 messages. The curl command can be used to list the number of messages in a queue and to purge all of the messages from the queue.
curl -X DELETE --user john.doe:itsasecret http://server001:15671/api/queues/%2f/foo.queue --if-empty=true
The --if-unused option can be included to only delete the queue if no consumers are using the queue.
curl -X DELETE --user john.doe:itsasecret http://server001:15671/api/queues/%2f/foo.queue --if-unused=true
Did you find this article helpful?
If so, consider buying me a coffee over at