RabbitMQ - Delete messages using the rabbitmqctl command

by
Jeremy Canfield |
Updated: February 23 2022
| RabbitMQ articles
The rabbitmqctl command with the purge_queues option can be used to purge (permanently delete) all of the messages in a queue. The messages cannot be recovered after they are purged.
rabbitmqctl purge_queue queue_name
Optionally, the -p option can be used to specify the virtual host (vhost).
rabbitmqctl purge_queue queue_name -p vhost001
Before purging a queue, the list_queues command can be used to list the number of messages in the queue. In this example, there are 17 messages in queue002.
~]# rabbitmqctl list_queues -p vhost001
Listing queues for vhost vhost001
name messages
queue001 0
queue002 17
You can specify the items you wish to include in the output, like this.
rabbitmqctl purge_queue queue002 -p vhost001
Something like this should be displayed.
Purging queue 'queue001' in vhost 'vhost001' ...
Did you find this article helpful?
If so, consider buying me a coffee over at