我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。
当前回答
删除非持久队列不需要重置rabbitmq服务器。只需停止服务器并重新启动,它就会删除所有可用的非持久队列。
其他回答
另一个选项是删除与队列关联的vhost。这将删除与vhost关联的所有内容,因此请注意,但这很简单且快速。
注意:RabbitMQ团队会监控RabbitMQ用户的邮件列表,有时只在StackOverflow上回答问题。
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
有一种方法可以在不使用脚本和完全重置的情况下删除所有队列和交换机。您可以从管理界面删除并重新创建虚拟主机。这甚至适用于vhost /。
您唯一需要恢复的是新创建的vhost的权限。
如果您试图删除队列,因为它们是未使用的,并且您不想重置,一个选项是通过策略将队列TTL设置得非常低,等待队列在TTL通过后自动删除,然后删除策略(https://www.rabbitmq.com/ttl.html)。
rabbitmqctl.bat set_policy delq ".*" '{"expires": 1}' --apply-to queues
删除策略
rabbitmqctl clear_policy delq
注意,这只适用于未使用的队列
原始信息在这里:http://rabbitmq.1065348.n5.nabble.com/Deleting-all-queues-in-rabbitmq-td30933.html
试试这个:
rabbitmqctl list_queues -q name > q.txt
IFS=$'\n' read -d '' -r -a queues < q.txt
count=${#queues[@]}
i=1; while (($i < $count)); do echo ${queues[$i]};rabbitmqctl delete_queue ${queues[$i]};i=$((i+1)); done