Removing Queues in RabbitMQ

I have several queues working with RabbitMQ. Some of them are useless now, how can I remove them? Unfortunately, I did not set the auto_delete parameter.

If I installed it now, will it be uninstalled?

Is there any way to remove these queues now?

+77
queue rabbitmq
Jul 19 '11 at 6:07
source share
13 answers

If you do not need other queues, you can remove them from the command line by running the following commands:

Warning: this will also delete all users and vhosts that you configured on your rabbit server p>

 rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl start_app 

The rabbitmq documentation states that the reset command:

Deletes a node from any cluster to which it belongs, deletes all data from the management database, such as configured users and vhosts, and deletes all persistent messages.

So be careful with that.

+107
Oct. 15 '12 at 8:56
source share

In versions of RabbitMQ> 3.0, you can also use the HTTP API if the rabbitmq_management plugin is enabled. Just remember to set the content type to "application / json" and specify the name vhost and queue:

those. Using curl with vhost 'test' and queue name 'testqueue':

 $ curl -i -u guest:guest -H "content-type:application/json" -XDELETE http://localhost:15672/api/queues/test/testqueue HTTP/1.1 204 No Content Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue) Date: Tue, 16 Apr 2013 10:37:48 GMT Content-Type: application/json Content-Length: 0 
+25
Apr 17 '13 at 14:28
source share
 import pika connection = pika.BlockingConnection(pika.ConnectionParameters( 'localhost')) channel = connection.channel() channel.queue_delete(queue='queue-name') connection.close() 

Install the pika package as follows

 $ sudo pip install pika==0.9.8 

Installation depends on pip and git -core packages, you may need to install them first.

In Ubuntu:

 $ sudo apt-get install python-pip git-core 

In 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 
+20
Nov 11 '13 at 19:14
source share

There is rabbitmqadmin , which is convenient to work with from the console.

If you ssh / log in to the server on which the rabbit is installed, you can download it from:

 http://{server}:15672/cli/rabbitmqadmin 

and save it to / usr / local / bin / rabbitmqadmin

Then you can run

 rabbitmqadmin -u {user} -p {password} -V {vhost} delete queue name={name} 

This usually requires sudo.

If you want to avoid entering a username and password, you can use config

 rabbitmqadmin -c /var/lib/rabbitmq/.rabbitmqadmin.conf -V {vhost} delete queue name={name} 

All that under the assumption that you have the file ** / var / lib / rabbitmq / .rabbitmqadmin.conf ** and there is a bare minute

 hostname = localhost port = 15672 username = {user} password = {password} 

EDIT: with comments from @ user299709, it may be helpful to indicate that the user should be marked as β€œadmin” in the rabbit. ( https://www.rabbitmq.com/management.html )

+17
Apr 17 '15 at 20:04
source share

You claim that there is a queue (and create it if it is missing) using queue.declare . If you initially set auto-delete to false, calling queue.declare again using autodelete true will result in a soft error, and the broker will close the channel.

Now you need to use queue.delete to remove it.

See the API documentation for more details:

If you are using another client, you need to find an equivalent method. Since this is part of the protocol, it should be there, and it is probably part of the channel or equivalent.

You can also see the rest of the documentation, in particular the Geting Started section, which covers many common use cases.

Finally, if you have a question and cannot find the answer elsewhere, you should try posting on the RabbitMQ Discussion mailing list. The developers are working hard to answer all the questions asked there.

+12
Jul 19 '11 at 7:44
source share

A quick tour to quickly delete a queue with all defaults from the host on which the RMQ server is running:

 curl -O http://localhost:15672/cli/rabbitmqadmin chmod u+x rabbitmqadmin ./rabbitmqadmin delete queue name=myQueueName 

To remove all queues matching the pattern in the given vhost (for example, containing "amq.gen" in the root vhost):

 rabbitmqctl -p / list_queues | grep 'amq.gen' | cut -f1 -d$'\t' | xargs -I % ./rabbitmqadmin -V / delete queue name=% 
+12
Dec 14 '15 at 20:15
source share

Another option is to enable enable_plugin and connect to it through a browser. You can view all the queues and information about them. It is possible to simply remove the queues from this interface.

+10
May 2 '12 at 11:13
source share

The control plugin (web interface) gives you a link to a python script. You can use it to delete queues. I used this template to delete many 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 
+6
Mar 21 '13 at 15:41
source share

I generalized the JavaScript / jQuery Piotr Stapp method a little further, encapsulating it in a function and generalizing it a bit.

This function uses the RabbitMQ HTTP API to query for available queues in the given vhost , and then removes them based on the optional queuePrefix :

 function deleteQueues(vhost, queuePrefix) { if (vhost === '/') vhost = '%2F'; // html encode forward slashes $.ajax({ url: '/api/queues/'+vhost, success: function(result) { $.each(result, function(i, queue) { if (queuePrefix && !queue.name.startsWith(queuePrefix)) return true; $.ajax({ url: '/api/queues/'+vhost+'/'+queue.name, type: 'DELETE', success: function(result) { console.log('deleted '+ queue.name)} }); }); } }); }; 

Once you insert this function into your browser JavaScript console while on the RabbitMQ control page, you can use it as follows:

Delete all queues in '/' vhost

 deleteQueues('/'); 

Delete all queues in '/' vhost starting with 'test'

 deleteQueues('/', 'test'); 

Delete all queues in 'dev' vhost starting with 'foo'

 deleteQueues('dev', 'foo'); 

Please use this at your own risk!

+6
Jan 14 '16 at 20:19
source share

I use this alias in .profile :

 alias qclean="rabbitmqctl list_queues | python ~/bin/qclean.py" 

where qclean.py has the following code:

 import sys import pika connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() queues = sys.stdin.readlines()[1:-1] for x in queues: q = x.split()[0] print 'Deleting %s...' %(q) channel.queue_delete(queue=q) connection.close() 

This is essentially an iterative version of Shweta B. Patil code.

+4
Mar 22 '14 at 10:37
source share

With the rabbitmq_management plugin installed, you can run this to remove all 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>/{} 

Release the command down:

rabbitmqctl list_queues -p vhost_name display all the queues and how many tasks they have.

grep -v "fast\|medium\|slow" will filter the queues that you do not want to delete, let's say that we want to delete each queue without words fast, medium or slow.

tr "[:blank:]" " " will normalize the divider on rabbitmqctl between the queue name and the number of tasks that are

cut -d " " -f 1 will separate each line with a space and select the 1st column (queue name)

xargs -I {} curl -i -u guest:guest -H "content-type:application/json" -XDELETE http://localhost:15672/api/queues/<vhost>/{} selects the queue name and sets it where we set the symbol {} , which will delete all the queues that are not filtered in the process.

Make sure that the user has administrator rights.

+3
Oct 18 '16 at 13:22
source share

I did it differently because I had access to the management web page. I created a simple "snippet" that removes queues in Javascript. There he is:

 function zeroPad(num, places) { var zero = places - num.toString().length + 1; return Array(+(zero > 0 && zero)).join("0") + num; } var queuePrefix = "PREFIX" for(var i=0; i<255; i++){ var queueid = zeroPad(i, 4); $.ajax({url: '/api/queues/vhost/'+queuePrefix+queueid, type: 'DELETE', success: function(result) {console.log('deleted '+queuePrefix+queueid)}}); } 

All my queues were in the format: PREFIX_0001 - PREFIX_0XXX

+2
Jul 25 '14 at 7:21
source share

to establish

 $ sudo rabbitmq-plugins enable rabbitmq_management 

and go to http: // localhost: 15672 / # / queues if you are using localhost. by default, the password will be the username: guest, password: guest and go to the queues tab and delete the queue.

+1
Nov 24 '17 at 7:48
source share



All Articles