我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。
当前回答
删除非持久队列不需要重置rabbitmq服务器。只需停止服务器并重新启动,它就会删除所有可用的非持久队列。
其他回答
首先,列出你的队列:
Rabbitmqadmin列表队列名称
然后从列表中,你需要逐个手动删除它们:
删除队列名
由于输出格式,您无法从列表队列中grep响应。或者,如果你只是在寻找一种方法来清除所有内容(读取:重置所有设置,将安装返回到默认状态),使用:
rabbitmqctl stop_app
rabbitmqctl reset # Be sure you really want to do this!
rabbitmqctl start_app
实际上管理插件和策略非常简单:
Goto管理控制台(localhost:15672) Goto管理选项卡 Goto Policies选项卡(在右侧) 添加政策 填充字段 虚拟主机:选择 名称:过期所有策略(稍后删除) 模式:. * 适用于:队列 定义:以值1到期(将类型从字符串更改为数字) 保存 签出队列选项卡 必须删除所有队列 不要忘记删除策略!!!!!!。
我做了一个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打印不同语言的输出更少见。
享受吧!
下面是一种使用PowerShell的方法。URL可能需要更新
$cred = Get-Credential
iwr -ContentType 'application/json' -Method Get -Credential $cred 'http://localhost:15672/api/queues' | % {
ConvertFrom-Json $_.Content } | % { $_ } | ? { $_.messages -gt 0} | % {
iwr -method DELETE -Credential $cred -uri $("http://localhost:15672/api/queues/{0}/{1}" -f [System.Web.HttpUtility]::UrlEncode($_.vhost), $_.name)
}
使用rabbitmqadmin,你可以用下面的一行程序删除它们:
rabbitmqadmin -f tsv -q list queues name | while read queue; do rabbitmqadmin -q delete queue name=${queue}; done