There are different options of how to purge a queue in RabbitMQ. The web based UI can be used via the RabbitMQ Management Interface, or a script can be used via rabbitmqadmin or HTTP API curl.
Delete messages via:
![rabbitmq questions RabbitMQ Questions](/img/blog/faq-rabbitmq.png)
RabbitMQ Management Interface
A queue can be purged from the RabbitMQ Management Interface. Click the Queue tab and go to the bottom of the page. You will find a dropdown "Delete / Purge" there. Press Purge to the right to empty the queue.
![Purge RabbitMQ message queue via the mgmt interface Purge RabbitMQ message queue via the mgmt interface](/img/blog/purge-queue-rabbitmq-management-interface.png)
rabbitmqadmin
The management plugin ships with a command line tool rabbitmqadmin which can perform the same actions as the web-based UI (the RabbitMQ management interface).
The script used to purge all messages in a single queue is:
$ rabbitmqadmin purge queue name=name_of_queue
In CloudAMQP the management plugin is assigned port 443 and the ssl flag has to be used, as shown below.
$ rabbitmqadmin --host=HOST --port=443 --ssl --vhost=VHOST --username=USERNAME --password=PASSWORD purge queue name=QUEUE_NAME
![Purge RabbitMQ message queue via rabbitmqadmin Purge RabbitMQ message queue via rabbitmqadmin](/img/blog/purge-queue-rabbitmqadmin.png)
Policy
Add a policy that matches the queue names with an max-lenght rule. A policy can be added by entering the Management Interface and then pressing the admin tab.
Don't forget to delete the policy after it has been applied.
![delete all messages in queue policy delete all messages in queue policy](/img/blog/delete-messages-in-queue-policy.png)
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/contents
![Purge RabbitMQ message queue via HTTP API, curl](/img/blog/purge_queue_curl.png)
Please email us at contact@cloudamqp.com if you have any suggestions, questions or feedback.