Delete all the queues from RabbitMQ?

2020-02-16 05:42发布

I installed rabbitmqadmin and was able to list all the exchanges and queues. How can I use rabbitmqadmin or rabbitmqctl to delete all the queues.

23条回答
看我几分像从前
2楼-- · 2020-02-16 06:11

Another option is to delete the vhost associated with the queues. This will delete everything associated with the vhost, so be warned, but it is easy and fast.


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.

查看更多
别忘想泡老子
3楼-- · 2020-02-16 06:12

If you're trying to delete queues because they're unused and you don't want to reset, one option is to set the queue TTL very low via a policy, wait for the queues to be auto-deleted once the TTL is passed and then remove the policy (https://www.rabbitmq.com/ttl.html).

rabbitmqctl.bat set_policy delq ".*" '{"expires": 1}' --apply-to queues

To remove the policy

rabbitmqctl clear_policy delq

Note that this only works for unused queues

Original info here: http://rabbitmq.1065348.n5.nabble.com/Deleting-all-queues-in-rabbitmq-td30933.html

查看更多
不美不萌又怎样
4楼-- · 2020-02-16 06:13

In case you only want to purge the queues which are not empty (a lot faster):

rabbitmqctl list_queues | awk '$2!=0 { print $1 }' | sed 's/Listing//' | xargs -L1 rabbitmqctl purge_queue

For me, it takes 2-3 seconds to purge a queue (both empty and non-empty ones), so iterating through 50 queues is such a pain while I just need to purge 10 of them (40/50 are empty).

查看更多
小情绪 Triste *
5楼-- · 2020-02-16 06:14

For whose have a problem with installing rabbitmqadmin, You should firstly install python.

UNIX-like operating system users need to copy rabbitmqadmin to a directory in PATH, e.g. /usr/local/bin.

Windows users will need to ensure Python is on their PATH, and invoke rabbitmqadmin as python.exe rabbitmqadmin.

Then

  1. Browse to http://{hostname}:15672/cli/rabbitmqadmin to download.
  2. Go to the containing folder then run cmd with administrator privilege

To list Queues python rabbitmqadmin list queues.

To delete Queue python rabbitmqadmin delete queue name=Name_of_queue

To Delete all Queues

1- Declare Policy

python rabbitmqadmin declare policy name='expire_all_policies' pattern=.* definition={\"expires\":1} apply-to=queues

2- Remove the policy

python rabbitmqadmin  delete policy name='expire_all_policies'
查看更多
做自己的国王
6楼-- · 2020-02-16 06:15

I tried rabbitmqctl and reset commands but they are very slow.

This is the fastest way I found (replace your username and password):

#!/bin/bash

# Stop on error
set -eo pipefail

USER='guest'
PASSWORD='guest'

curl -sSL -u $USER:$PASSWORD http://localhost:15672/api/queues/%2f/ | jq '.[].name' | sed 's/"//g' | xargs -L 1 -I@ curl -XDELETE -sSL -u $USER:$PASSWORD http://localhost:15672/api/queues/%2f/@
# To also delete exchanges uncomment next line
# curl -sSL -u $USER:$PASSWORD http://localhost:15672/api/exchanges/%2f/ | jq '.[].name' | sed 's/"//g' | xargs -L 1 -I@ curl -XDELETE -sSL -u $USER:$PASSWORD http://localhost:15672/api/exchanges/%2f/@

Note: This only works with the default vhost /

查看更多
登录 后发表回答