我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。
当前回答
如https://stackoverflow.com/a/52002145/3278855
要实现自动化,可以使用curl:
curl -X PUT --data '{"pattern":".*","apply-to":"all","definition":{"expires":1},"priority":0}' -u guest:guest 'http://localhost:15672/api/policies/%2f/clear' && \
curl -X DELETE -u guest:guest 'http://localhost:15672/api/policies/%2f/clear'
请注意%2f是默认的v主机名(/),guest:guest是登录名:密码
其他回答
首先,列出你的队列:
Rabbitmqadmin列表队列名称
然后从列表中,你需要逐个手动删除它们:
删除队列名
由于输出格式,您无法从列表队列中grep响应。或者,如果你只是在寻找一种方法来清除所有内容(读取:重置所有设置,将安装返回到默认状态),使用:
rabbitmqctl stop_app
rabbitmqctl reset # Be sure you really want to do this!
rabbitmqctl start_app
我做了一个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打印不同语言的输出更少见。
享受吧!
实际上管理插件和策略非常简单:
Goto管理控制台(localhost:15672) Goto管理选项卡 Goto Policies选项卡(在右侧) 添加政策 填充字段 虚拟主机:选择 名称:过期所有策略(稍后删除) 模式:. * 适用于:队列 定义:以值1到期(将类型从字符串更改为数字) 保存 签出队列选项卡 必须删除所有队列 不要忘记删除策略!!!!!!。
试试这个:
rabbitmqadmin list queues name | awk '{print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn
删除非持久队列不需要重置rabbitmq服务器。只需停止服务器并重新启动,它就会删除所有可用的非持久队列。