# FAQ: How to delete all messages from a Queue

By Lovisa Johansson. Published 14 June 2016.

Frequently Asked RabbitMQ Question: How do we delete all messages in a queue? This article explains how to empty a single RabbitMQ Message Queue.

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 Management Interface](/blog/how-to-delete-all-messages-in-a-queue/#mgmt_interface)
- [rabbitmqadmin](/blog/how-to-delete-all-messages-in-a-queue/#rabbitmqadmin)
- [Policy](/blog/how-to-delete-all-messages-in-a-queue/#policy)
- [HTTP API curl](/blog/how-to-delete-all-messages-in-a-queue/#http_api_curl)

![RabbitMQ Questions](/img/blog/faq-rabbitmq.png "rabbitmq questions")

### 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](/img/blog/purge-queue-rabbitmq-management-interface.png "Purge RabbitMQ message queue via the mgmt interface")
### rabbitmqadmin

The management plugin ships with a command line tool **[rabbitmqadmin](https://www.rabbitmq.com/management-cli.html)** which can perform the same actions as the web-based UI (the RabbitMQ management interface).

**Note:** When using rabbitmqadmin externally, you will need to connect to your instance with TLS and a username and password must be provided. In CloudAMQP, the management plugin is assigned port 443.

If you do not have a TLS certificate you can find one **[here](https://www.cloudamqp.com/docs/faq/#how-do-i-authenticate-the-identity-of-your-server).** You can obtain all other information from the dashboard of the CloudAMQP console for your instance. It is recommended that you collect your login information into a config file, "admin.conf", shown below. You can also run the commands without the config by setting each part of the config as a flag in the command (eg. password becomes --password=PASSWORD)

Rabbitmqadmin config example, ensure all text is contained in quote marks as shown:

```bash
[default]
hostname = "CLUSTER_URL"
port = 443
username = "USERNAME"
password = "PASSWORD"
vhost = "VHOST"
```

The command used to purge all messages in a single queue is:

```bash
$ rabbitmqadmin purge queue name=name_of_queue
```

The example below shows how the command is used for a CloudAMQP instance.

```bash
$ rabbitmqadmin --use-tls --tls-ca-cert-file=$CERTIFICATE_LOCATION --config=$CONFIG_LOCATION purge queue name=name_of_queue
```

### Policy

Add a policy that matches the queue names with an max-length 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](/img/blog/delete-messages-in-queue-policy.png "delete all messages in queue policy")

### 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](mailto:contact@cloudamqp.com) if you have any suggestions, questions or feedback.
