【问题标题】:How to purge all rabbitmq queues in python by queue name如何按队列名称清除python中的所有rabbitmq队列
【发布时间】:2020-10-06 16:21:24
【问题描述】:

我使用 python kombu 包与 rabbitmq 服务进行交互。 我想清除所有队列。我看到有一个kombu.Queue.purge 方法,但我不想创建kombu.Queue 对象,因为我不知道哪些交换连接到哪些队列。我只想使用队列名称。

【问题讨论】:

    标签: python rabbitmq message-queue


    【解决方案1】:

    kombu Channel 类实现了一个 queue_purge 方法,该方法可以清除给定名称的队列。

    以下代码列出所有队列并根据它们的名称清除它们。

    from kombu import Connection
    
    # Create a connection
    mq_conn_string = 'amqp://user:password@domain:port//'  # Set the correct credentials
    mq_conn = Connection(mq_conn_string)
    mq_conn.connect()
    
    # Create a channel
    channel = mq_conn.channel()
    
    # Get all queues
    vhost = "/"
    manager = mq_conn.get_manager()
    queues = manager.get_queues(vhost)
    
    # Purge each queue
    for queue in queues:
        queue_name = queue["name"]
        channel.queue_purge(queue_name)
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-05
      • 2017-12-27
      • 2012-07-12
      • 2022-08-19
      • 2015-06-13
      • 2014-09-26
      相关资源
      最近更新 更多