【问题标题】:How to delete a queue in rabbit mq如何在rabbitmq中删除队列
【发布时间】:2013-11-23 14:36:02
【问题描述】:

我正在使用 rabbitmctl 和 pika 库。 我使用下面的代码来创建一个Producer

#!/usr/bin/env python
import pika
import time
import json
import datetime


connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='localhost'))
channel = connection.channel()



channel.queue_declare(queue='hello')

def callback(ch, method, properties, body):
    #print " current time: %s "  % (str(int((time.time())*1000)))

    print body

channel.basic_consume(callback,
                      queue='hello',
                      no_ack=True)


channel.start_consuming()

由于我每次都创建一个现有队列(如果未创建队列,则覆盖队列的创建)队列已因此而损坏。现在我想删除队列..我该怎么做?

【问题讨论】:

    标签: queue rabbitmq


    【解决方案1】:

    由于这似乎是一个维护过程,而不是您经常对代码执行的操作,您可能应该使用RabbitMQ management plugin 并从那里删除队列。

    无论如何,您可以使用以下命令从 pika 中删除它:

    channel.queue_delete(queue='hello')
    

    https://pika.readthedocs.org/en/latest/modules/channel.html#pika.channel.Channel.queue_delete

    【讨论】:

      【解决方案2】:

      详细答案如下(参考上面非常有帮助和有用的答案)

      import pika
      
      
      connection = pika.BlockingConnection(pika.ConnectionParameters(
                     'localhost'))
      channel = connection.channel()
      
      
      channel.queue_delete(queue='hello')
      
      connection.close()
      

      【讨论】:

        【解决方案3】:

        GUI rabbitMQ mgm 没那么容易

        $ sudo rabbitmq-plugins enable rabbitmq_management
        

        http://localhost:15672/#/queues

        用户名:访客

        密码:访客


        灵感来自this

        【讨论】: