我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。


当前回答

rabbitmqadmin list queues|awk 'NR>3{print $4}'|head -n-1|xargs -I qname rabbitmqadmin delete queue name=qname

其他回答

这是我使用的方法。它简单、清晰、有效。 文件如下:

Vhost=the_vhost_name
User=user_name
Password=the_passworld

for i in `rabbitmqctl list_queues -p $Vhost |  awk '{ print $1 }'`
do
    echo "queu_name: $i"
    curl  -u $User:$Passworld -H "content-type:application/json"  -XDELETE http://localhost:15672/api/queues/$Vhost/$i
done 

试试这个:

 rabbitmqadmin list queues name | awk '{print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn
rabbitmqadmin list queues|awk 'NR>3{print $4}'|head -n-1|xargs -I qname rabbitmqadmin delete queue name=qname

Okay, important qualifier for this answer: The question does ask to use either rabbitmqctl OR rabbitmqadmin to solve this, my answer needed to use both. Also, note that this was tested on MacOS 10.12.6 and the versions of the rabbitmqctl and rabbitmqadmin that are installed when installing rabbitmq with Homebrew and which is identified with brew list --versions as rabbitmq 3.7.0 rabbitmqctl list_queues -p <VIRTUAL_HOSTNAME> name | sed 1,2d | xargs -I qname rabbitmqadmin --vhost <VIRTUAL_HOSTNAME> delete queue name=qname

该命令删除所有队列

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={}

这个脚本非常简单,因为它使用了-f bash,它以列表的形式输出队列。

然后我们使用xargs -n1将其拆分为多个变量

然后我们使用xargs -I{}来运行下面的命令,并替换命令中的{}。