代码之家  ›  专栏  ›  技术社区  ›  Shan Khan

如何获取Pika RabbitMQ中的所有挂起任务和清除队列

  •  0
  • Shan Khan  · 技术社区  · 7 年前

    我想将队列中所有挂起的任务保存到数据库中。 并从队列中移除这些任务。

    我知道 channel.purgeQueue

    我需要知道队列中挂起的任务。

    如何得到它们

    1 回复  |  直到 7 年前
        1
  •  0
  •   Gabriele Santomaggio    7 年前

    这是RabbitMQ的基本功能,请阅读以下内容:

    https://www.rabbitmq.com/tutorials/tutorial-two-python.html

    您要查找的代码是:

    def callback(ch, method, properties, body):
        print " [x] Received %r" % (body,)
        ### PUT_YOUR_CODE_HERE
        print " [x] Done"
        ch.basic_ack(delivery_tag = method.delivery_tag)
    
    channel.basic_consume(callback,
                          queue='hello')
    

    当您执行 ch.basic_ack 消息将从队列中删除

    推荐文章