我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。
当前回答
我做了一个deleteRabbitMqQs.sh,它接受参数来搜索队列列表,只选择与您想要的模式匹配的参数。如果你没有提供参数,它会将它们全部删除!它向您显示即将删除的队列列表,让您在执行任何破坏性操作之前退出。
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"
如果想要对传入的参数进行不同的匹配,可以在第4行中更改grep。当删除所有队列时,它不会删除其中有三个连续空格的队列,因为我认为这种情况比使用rabbitmqctl打印不同语言的输出更少见。
享受吧!
其他回答
下面的命令对我有用:
sudo rabbitmqctl list_queues | awk '{print $1}' | xargs -I qn sudo rabbitmqctl delete_queue qn
试试这个:
rabbitmqadmin list queues name | awk '{print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn
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
要列出队列,
./rabbitmqadmin -f tsv -q list queues
要删除一个队列,
./rabbitmqadmin delete queue name=name_of_queue
首先,列出你的队列:
Rabbitmqadmin列表队列名称
然后从列表中,你需要逐个手动删除它们:
删除队列名
由于输出格式,您无法从列表队列中grep响应。或者,如果你只是在寻找一种方法来清除所有内容(读取:重置所有设置,将安装返回到默认状态),使用:
rabbitmqctl stop_app
rabbitmqctl reset # Be sure you really want to do this!
rabbitmqctl start_app