Create instructions on how to remove all queues from RabbitMQ
I sometimes need to stop celery and remove all queues before restarting celery again. This can be useful when a query isn't working properly, for example.
At the moment I do this by going to the web interface of RabbitMQ and manually deleting each queue. This is time-consuming.
It can be scripted instead.
You need to download the python rabbitmqadmin script for your install (see https://www.rabbitmq.com/management-cli.html).
This can then be used to obtain a list of the queues (https://www.cloudamqp.com/blog/2016-06-21-how-to-delete-queues-in-rabbitmq.html), the output of which can be used to delete them.
I've not implemented this on Windows yet, but plan to.
Comments (37)
-
reporter -
reporter On my Windows system it turns out that there's no need to stop celery before deleting the queues because celery automatically re-creates the essential queues on deletion. So, the following works for me (confirmed as working):
ECHO OFF ::----------------------------------------------------------------------------- :: Set up some variables :: Reminder: there must not be any whitespace on either side of the equals when :: assigning variables in a batch file. :: :: The python executable (you may need to include the full path). SET python_exe=python.exe :: The rabbitmqadmin.py script. You need to create this file by following the :: instructions here: https://www.rabbitmq.com/management-cli.html SET rabbitmqadmin=D:\Server_Apps\rabbit_mq\rabbitmq_server-3.6.9\rabbitmqadmin.py :: The path and file name of a temporary file to store the queue names SET q_names=E:\rabbit_mq\q_names.txt ::----------------------------------------------------------------------------- ::----------------------------------------------------------------------------- :: Now remove all entries in rabbitmq :: First obtain a list of all the RabbitMQ queue names and save this to a file. %python_exe% %rabbitmqadmin% -f tsv -q list queues name > %q_names% :: Next, read in the name of each queue from the file and delete that queue FOR /F "tokens=*" %%A IN (%q_names%) DO %python_exe% %rabbitmqadmin% delete queue name=%%A ::-----------------------------------------------------------------------------
@edmcdonagh, I'm sure there's a simple way of scripting the equivalent to this in Linux...
-
You presumably need to install the RabbitMQ management software?
-
Scrap that I can see I just needed to run
sudo rabbitmq-plugins enable rabbitmq_management
then browse to http://localhost:15672/cli/rabbitmqadmin to get the python file. -
reporter On Windows you need to enable the rabbitmq management plugin (https://www.rabbitmq.com/management.html) and then browse to the same link you mention above.
-
Having a quick look at the API, it wouldn't be hard to have a page in the web interface that reports on queue lengths, aliveness and enables queue clearing. http://localhost:15672/api/
-
reporter You're right - it looks like using the api would enable this to be done via a web interface. As well as the coding it would involve adding instructions on how to install the RabbitMQ management plugin, but that isn't too involved.
-
We'd need to use the requests python library to interact using PUT and DELETE in addition to POST and GET: http://docs.python-requests.org/en/master/api/
-
Adding enabling RabbitMQ management interface to linux single page install. Refs
#637,#662→ <<cset e72312a857b4>>
-
Adding enabling RabbitMQ management interface to standard pre-install instructions. Refs
#637,#662→ <<cset c1c847ba1c31>>
-
Correcting code block . Refs
#637,#662. [skip ci] docs only→ <<cset 08b4c47d8ced>>
-
Adding an indent to the Linux instructions. Refs
#637,#662. [skip ci] docs only→ <<cset 4cf00f1b1fb0>>
-
Simple (and crude) check on the length of the RabbitMQ default queue on the localhost. Not clear if it needs to be the hostname. Refs
#637,#662→ <<cset e76c39c6c128>>
-
Still crude, but now lists each queue in a table. Refs
#637,#662→ <<cset 9ab44917148b>>
-
Finally clicked why pipelines were failing... Refs
#637,#662→ <<cset 396be014d7e9>>
-
Added more detail to table and added purge button. Refs
#637,#662→ <<cset bef421068d47>>
-
Removed redundant function/URL. Refs
#637,#662→ <<cset 59ad6956f896>>
-
-
Spelling correction. Refs
#637,#662→ <<cset 4af1303162d2>>
-
Now deals with management interface not enabled. Also tested from separate system. Refs
#637,#662→ <<cset fe8d6cf7637e>>
-
Adding docs for RabbitMQ admin page. Refs
#637,#662→ <<cset 02ef84e58f4a>>
-
Attempting to get RabbitMQ docs built from the right paren. Refs
#637,#662[skip ci} docs only→ <<cset 4bc5dbc2a159>>
-
Small changes to docs. Refs
#637,#662[skip ci} docs only→ <<cset 26fde314e181>>
-
Split out creation of admin user, not necessary. Updated release notes. Added docs link. Set docs version to make links work for PR. Refs
#637,#662[skip ci} docs only→ <<cset f8669e08c1db>>
-
Added missing docstring. Thanks Codacy! Refs
#637,#662→ <<cset 965d4b65ce4f>>
-
Adding missing code block declaration. Refs
#637,#662→ <<cset 052ce5d72140>>
-
Updated changes - will close both issues with this PR. Bumped version of release notes to render, moved 0.8.1 to history. Refs
#637,#662[skip ci] docs only→ <<cset 83f88a5c2557>>
-
Updating title for 0.8.1 release notes. Refs
#637,#662[skip ci] docs only→ <<cset 6c1a6bf2de5e>>
-
non-static-URL version confirmed working by @LuukO, also by me. Don't know what has changed...! Refs
#637,#662→ <<cset 08b9388d2eac>>
-
- changed status to resolved
Merged in issue637-662RabbitMQmanagement (pull request #241)
Approved-by: Luuk Approved-by: David Platten
→ <<cset c7ed191113ef>>
-
- changed milestone to 0.9.0
-
Moved statuses and jobs waiting to celery page. Need to add terminate RabbitMQ queued jobs, then can remove RabbitMQ page. Refs
#637,#662,#705[skip ci]→ <<cset 4099a54b8476>>
-
Added button to purge RabbitMQ queue. Refs
#637,#662,#705[skip ci]→ <<cset 81e397a23070>>
-
Removed RabbitMQ url, views, templates. Refs
#637,#662,#705[skip ci]→ <<cset 2ddd46f902e4>>
-
New titles, links to docs, removed non-useful text. Refs
#637,#662,#705[skip ci]→ <<cset 12d64f7dfa6d>>
-
Removing hyphen in message-broker. Refs
#637sort of.→ <<cset 0c6576dbb44a>>
-
Merged in issue349celery (pull request #277)
RabbitMQ, Celery and Flower task management changes
Fixes
#349,#705,#723, refs#637,#662Approved-by: Luuk Approved-by: David Platten
→ <<cset f4bb4875a6fc>>
- Log in to comment
A Windows batch file as a work-in-progress to stop celery, delete all RabbitMQ jobs and then restart celery: