How to delete single or multiple queues in RabbitMQ

Frequently Asked RabbitMQ Question: We created 1000+ queues by accident - how do we delete them? This article explains how to delete single or multiple queues in RabbitMQ.

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 Frequently Asked Questions

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.

Purge RabbitMQ message queue via the mgmt interface

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 RabbitMQ message queue

Delete multiple queues

The script below will:

  1. 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.
  2. 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
delete multiple queue rabbitmq

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.

Policy to auto delete queues in RabbitMQ Policy to auto delete queues in RabbitMQ

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 delete RabbitMQ message queue via HTTP API, curl

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.

CloudAMQP - industry leading RabbitMQ as a service

Start your managed cluster today. CloudAMQP is 100% free to try.

13,000+ users including these smart companies