【发布时间】:2011-10-27 03:40:50
【问题描述】:
似乎我的 rabbitmq 服务器运行时间越长,未确认消息的问题就越多。我很想重新排队。实际上,似乎有一个 amqp 命令可以执行此操作,但它仅适用于您的连接正在使用的通道。我构建了一个小鼠兔脚本至少可以尝试一下,但是我要么遗漏了一些东西,要么无法以这种方式完成(用 rabbitmqctl 怎么样?)
import pika
credentials = pika.PlainCredentials('***', '***')
parameters = pika.ConnectionParameters(host='localhost',port=5672,\
credentials=credentials, virtual_host='***')
def handle_delivery(body):
"""Called when we receive a message from RabbitMQ"""
print body
def on_connected(connection):
"""Called when we are fully connected to RabbitMQ"""
connection.channel(on_channel_open)
def on_channel_open(new_channel):
"""Called when our channel has opened"""
global channel
channel = new_channel
channel.basic_recover(callback=handle_delivery,requeue=True)
try:
connection = pika.SelectConnection(parameters=parameters,\
on_open_callback=on_connected)
# Loop so we can communicate with RabbitMQ
connection.ioloop.start()
except KeyboardInterrupt:
# Gracefully close the connection
connection.close()
# Loop until we're fully closed, will stop on its own
connection.ioloop.start()
【问题讨论】:
-
你能解决这个问题吗?
-
stackoverflow.com/questions/8296201/… SO 答案可能需要什么,这取决于您为什么还有其他频道仍然挂着未确认的消息。僵尸频道。不重复,因为这个主题是关于其他频道中的消息,而不是频道本身。
标签: rabbitmq celery amqp pika celeryd