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:05

To list queues,

./rabbitmqadmin -f tsv -q list queues

To delete a queue,

./rabbitmqadmin delete queue name=name_of_queue
查看更多
不美不萌又怎样
3楼-- · 2020-02-16 06:05

Here is a faster version (using parallel install sudo apt-get install parallel) expanding on the excellent answer by @admenva

parallel -j 50 rabbitmqadmin -H YOUR_HOST_OR_LOCALHOST -q delete queue name={} ::: $(rabbitmqadmin -H YOUR_HOST_OR_LOCALHOST -f tsv -q list queues name)

查看更多
Emotional °昔
4楼-- · 2020-02-16 06:08

This commands deletes all your queues

python rabbitmqadmin.py \
  -H YOURHOST -u guest -p guest -f bash list queues | \
xargs -n1 | \
xargs -I{} \
  python rabbitmqadmin.py -H YOURHOST -u guest -p guest delete queue name={}

This script is super simple because it uses -f bash, which outputs the queues as a list.

Then we use xargs -n1 to split that up into multiple variables

Then we use xargs -I{} that will run the command following, and replace {} in the command.

查看更多
贼婆χ
5楼-- · 2020-02-16 06:09

First, list your queues:

rabbitmqadmin list queues name

Then from the list, you'll need to manually delete them one by one:

rabbitmqadmin delete queue name='queuename'

Because of the output format, doesn't appear you can grep the response from list queues. Alternatively, if you're just looking for a way to clear everything (read: reset all settings, returning the installation to a default state), use:

rabbitmqctl stop_app
rabbitmqctl reset    # Be sure you really want to do this!
rabbitmqctl start_app
查看更多
乱世女痞
6楼-- · 2020-02-16 06:09

If you don't have rabbitmqadmin installed, try to purge queues with rabbitmqctl:

rabbitmqctl list_queues | awk '{ print $1 }' | xargs -L1 rabbitmqctl purge_queue

查看更多
看我几分像从前
7楼-- · 2020-02-16 06:11

I made a deleteRabbitMqQs.sh, which accepts arguments to search the list of queues for, selecting only ones matching the pattern you want. If you offer no arguments, it will delete them all! It shows you the list of queues its about to delete, letting you quit before doing anything destructive.

for word in "$@"
do
        args=true
        newQueues=$(rabbitmqctl list_queues name | grep "$word")
        queues="$queues
$newQueues"
done
if [ $# -eq 0 ]; then
        queues=$(rabbitmqctl list_queues name | grep -v "\.\.\.")
fi

queues=$(echo "$queues" | sed '/^[[:space:]]*$/d')

if [ "x$queues" == "x" ]; then
        echo "No queues to delete, giving up."
        exit 0
fi

read -p "Deleting the following queues:
${queues}
[CTRL+C quit | ENTER proceed]
"

while read -r line; do
        rabbitmqadmin delete queue name="$line"
done <<< "$queues"

If you want different matching against the arguments you pass in, you can alter the grep in line four. When deleting all queues, it won't delete ones with three consecutive spaces in them, because I figured that eventuality would be rarer than people who have rabbitmqctl printing its output out in different languages.

Enjoy!

查看更多
登录 后发表回答