I have a few queues running with RabbitMQ. A few of them are of no use now, how can I delete them? Unfortunately I had not set the auto_delete option.
If I set it now, will it be deleted?
Is there a way to delete those queues now?
I have a few queues running with RabbitMQ. A few of them are of no use now, how can I delete them? Unfortunately I had not set the auto_delete option.
If I set it now, will it be deleted?
Is there a way to delete those queues now?
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
'localhost'))
channel = connection.channel()
channel.queue_delete(queue='queue-name')
connection.close()
Install pika package as follows
$ sudo pip install pika==0.9.8
The installation depends on pip and git-core packages, you may need to install them first.
On Ubuntu:
$ sudo apt-get install python-pip git-core
On Debian:
$ sudo apt-get install python-setuptools git-core
$ sudo easy_install pip
On Windows: To install easy_install, run the MS Windows Installer for setuptools
> easy_install pip
> pip install pika==0.9.8
install
$ sudo rabbitmq-plugins enable rabbitmq_management
and go to http://localhost:15672/#/queues if you are using localhost. the default password will be username: guest, password: guest
and go to queues tab and delete the queue.
Hopefully it might help someone.
I tried the above pieces of code but I did not do any streaming.
sudo rabbitmqctl list_queues | awk '{print $1}' > queues.txt; for line in $(cat queues.txt); do sudo rabbitmqctl delete_queue "$line"; done.
I generate a file that contains all the queue names and loops through it line by line to the delete them. For the loops, while read ... did not do it for me. It was always stopping at the first queue name.
Also, if you want to delete a single queue, the above solutions will help(python, Java ...) and also do sudo rabbitmqctl delete_queue queue_name. I am using rabbitmqctl instead of rabbitmqadmin.
With the rabbitmq_management plugin installed you can run this to delete all the unwanted queues:
rabbitmqctl list_queues -p vhost_name |\
grep -v "fast\|medium\|slow" |\
tr "[:blank:]" " " |\
cut -d " " -f 1 |\
xargs -I {} curl -i -u guest:guest -H "content-type:application/json" -XDELETE http://localhost:15672/api/queues/<vhost_name>/{}
Let's break the command down:
rabbitmqctl list_queues -p vhost_name will list all the queues and how many task they have currently.
grep -v "fast\|medium\|slow" will filter the queues you don't want to delete, let's say we want to delete every queue without the words fast, medium or slow.
tr "[:blank:]" " " will normalize the delimiter on rabbitmqctl between the name of the queue and the amount of tasks there are
cut -d " " -f 1 will split each line by the whitespace and pick the 1st column (the queue name)
xargs -I {} curl -i -u guest:guest -H "content-type:application/json" -XDELETE http://localhost:15672/api/queues/<vhost>/{} will pick up the queue name and will set it into where we set the {} character deleting all queues not filtered in the process.
Be sure the user been used has administrator permissions.
I was struggling with finding an answer that suited my needs of manually delete a queue in rabbigmq. I therefore think it is worth mentioning in this thread that it is possible to delete a single queue without rabbitmqadmin using the following command:
rabbitmqctl delete_queue <queue_name>
If you are using C#, you can use HareDu API like so:
var result = await _services.GetService<IBrokerObjectFactory>()
.DeleteQueue("queue", "vhost");
...or
var result = await _services.GetService<IBrokerObjectFactory>()
.DeleteQueue("queue", "vhost", x =>
{
x.WhenHasNoConsumers();
x.WhenEmpty();
});
https://github.com/ahives/HareDu2/blob/master/docs/queue-delete.md