RabbitMQ
Queue Management
Data Deletion
Server Maintenance
IT Solutions

RabbitMQ: delete all queues with rabbitmqctl or rabbitmqadmin

Codemia Knowledge Hub ·

To delete all queues in RabbitMQ, list the queue names and delete each one from the command line, either with rabbitmqctl (installed with the server) or with rabbitmqadmin (from the Management Plugin). The web UI works for a handful of queues but not for bulk deletion.

People usually need this in testing and development (to reset RabbitMQ for consistent test results), for maintenance (removing unused or temporary queues to free resources) or for disaster recovery (resetting the system state). A queue holds messages until client applications consume them, and is bound to exchanges that route messages to it based on routing patterns and bindings, so deleting queues also removes whatever messages they hold.

Deleting all queues with rabbitmqctl

bash
  rabbitmqctl list_queues name --silent | while read queue; do rabbitmqctl delete_queue "$queue"; done

--silent drops the "Listing queues ..." banner and the name header row, so only queue names reach the loop.

Deleting all queues with rabbitmqadmin

rabbitmqadmin is a command-line tool available through the Management Plugin:

bash
  rabbitmqadmin -f tsv -q list queues name | xargs -I {} rabbitmqadmin -q delete queue name={}

-f tsv prints bare names instead of the default bordered table.

Deleting queues in the Management UI

The Management Plugin also provides a web UI and HTTP API:

  1. Open the Management UI, usually at http://server-name:15672/.
  2. Go to the Queues tab to see all queues.
  3. Select queues and delete them. This is impractical for a large number of queues.

Scripting deletion with Python and pika

For regular cleanup you can script deletion in bash or in Python with the pika library. AMQP has no command that lists queues, so the script below reads the queue names from the management HTTP API and then calls channel.queue_delete for each one.

python
1import pika
2import requests
3
4# Get the queue names from the management HTTP API (default vhost "/")
5queues = requests.get('http://localhost:15672/api/queues/%2F', auth=('guest', 'guest')).json()
6
7# Setup connection
8connection_params = pika.ConnectionParameters('localhost')
9connection = pika.BlockingConnection(connection_params)
10channel = connection.channel()
11
12# Delete each queue
13for queue in queues:
14    channel.queue_delete(queue=queue['name'])
15
16connection.close()

Before you bulk-delete

  • Persistent messages: make sure you are not deleting queues that hold important persistent messages.
  • Active clients: check that no consumer or publisher is using the queues, or you will disrupt running processes.
  • Backups: back up important data first, especially in production.
FeatureToolUse CaseCommand/Method
Delete Single QueueManagement UIManual operationsUse the delete option in the UI
Delete All QueuesrabbitmqctlAutomation and scriptsrabbitmqctl list\_queues name --silent | while read queue; do rabbitmqctl delete\_queue "$queue"; done
Delete All QueuesrabbitmqadminAdvanced command-line userabbitmqadmin -f tsv -q list queues name | xargs -I {} rabbitmqadmin -q delete queue name={}
Automation ScriptPython pikaAutomated, programmatic deletionHTTP API for names, then queue_delete

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design