There are different options to delete queues in RabbitMQ. The web-based UI can be used via the RabbitMQ Management Interface, a queue policy can be added or a script can be used via rabbitmqadmin or HTTP API curl. A script or a queue policy is recommended to delete multiple queues.
Delete queues via:RabbitMQ Management Interface
A queue can be deleted from the RabbitMQ Management Interface. Enter the queue tab and go to the bottom of the page. You will find a dropdown "Delete / Purge". Press Delete to the left to delete the queue.
rabbitmqadmin
The management plugin ships with a command-line tool named rabbitmqadmin, which can perform the same actions as the web-based UI (the RabbitMQ management interface).
Delete one queue:
$ rabbitmqadmin delete queue name=name_of_queue
In CloudAMQP the management plugin is assigned port 443 and the SSL flag is used as shown below.
$ rabbitmqadmin --host=HOST --port=443 --ssl --vhost=VHOST --username=USERNAME --password=PASSWORD delete queue name=QUEUE_NAME
Delete multiple queues
The script below will:
- Add all queues into a file called q.txt. You can open the file and remove the queues from the file that you would like to keep.
- Loop the list of queues and delete each one, as necessary.
$ rabbitmqadmin -f tsv -q list queues name > q.txt
$ while read -r name; do rabbitmqadmin -q delete queue name="${name}"; done < q.txt
In CloudAMQP, the management plugin is assigned port 443 and the SSL flag is used as shown below:
$ rabbitmqadmin --host=HOST --port=443 --ssl --vhost=VHOST --username=USERNAME --password=PASSWORD -f tsv -q list queues name > q.txt
$ while read -r name; do rabbitmqadmin -q --host=HOST --port=443 --ssl --vhost=VHOST --username=USERNAME --password=PASSWORD delete queue name="${name}"; done < q.txt
Policy
Add a policy that matches the queue names with an auto expire rule. A policy can be added by entering the Management Interface and then pressing the admin tab.
Note that this will only work for unused queues, and don't forget to delete the policy after it has been applied.
HTTP API, curl
The RabbitMQ Management plugin provides an HTTP-based API for management and monitoring of your RabbitMQ server. In CloudAMQP the management plugin is assigned port 443 and SSL has to be used.
curl -i -XDELETE https://USERNAME:PASSWORD@HOST/api/queues/rdkfegbx/QUEUE_NAME
If you want to only delete it once it is empty and has now consumers you can use the following option:
curl -XDELETE https://USERNAME:PASSWORD@HOST/api/queues/VHOST/QUEUE_NAME -G -d 'if-empty=true' -d 'if-unused=true'
Please email us at contact@cloudamqp.com if you have any suggestions, questions or feedback.