You assert that a queue exists (and create it if it does not) by using queue.declare. If you originally set auto-delete to false, calling queue.declare again with autodelete true will result in a soft error and the broker will close the channel.
You need to use queue.delete now in order to delete it.
If you use another client, you'll need to find the equivalent method. Since it's part of the protocol, it should be there, and it's probably part of Channel or the equivalent.
You might also want to have a look at the rest of the documentation, in particular the Geting Started section which covers a lot of common use cases.
Finally, if you have a question and can't find the answer elsewhere, you should try posting on the RabbitMQ Discuss mailing list. The developers do their best to answer all questions asked there.
Another option would be to enable the management_plugin and connect to it over a browser. You can see all queues and information about them. It is possible and simple to delete queues from this interface.
If you do not care about the data in management database; i.e. users, vhosts, messages etc., and neither about other queues, then you can reset via commandline by running the following commands in order:
WARNING: In addition to the queues, this will also remove any users and vhosts, you have configured on your RabbitMQ server; and will delete any persistent messages
Removes the node from any cluster it belongs to, removes all data from
the management database, such as configured users and vhosts, and
deletes all persistent messages.
The management plugin (web interface) gives you a link to a python script. You can use it to delete queues. I used this pattern to remove a lot of queues:
python tmp/rabbitmqadmin --vhost=... --username=... --password=... list queues > tmp/q
vi tmp/q # remove all queues which you want to keep
cut -d' ' -f4 tmp/q| while read q;
do python tmp/rabbitmqadmin --vhost=... --username=... --password=... delete queue name=$q;
done
In RabbitMQ versions > 3.0, you can also utilize the HTTP API if the rabbitmq_management plugin is enabled. Just be sure to set the content-type to 'application/json' and provide the vhost and queue name:
I.E. Using curl with a vhost 'test' and queue name 'testqueue':
EDIT: As of comment from @user299709, it might be helpful to point out that user must be tagged as 'administrator' in rabbit. (https://www.rabbitmq.com/management.html)
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.
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.
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.
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: