【发布时间】:2014-09-04 18:59:25
【问题描述】:
我需要遍历回调队列中的所有消息,然后关闭回调。一旦队列为空,我需要它停止消费。 所以我将消息从一个队列写入另一个队列。
creds = pika.PlainCredentials(app.config['mq.user'], app.config['mq.pass'])
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=app.config['mq.host'],
credentials=creds))
connection2 = pika.BlockingConnection(pika.ConnectionParameters(
host=app.config['mq.host'],
credentials=creds))
channel = connection.channel()
channel2 = connection2.channel()
Def requeue_callback(ch, method, properties, body):
try:
msg = json.loads(body)
ch2.basic_publish(exchange='',
routing_key=base_queue+'.request',
body = msg['orig_msg'])
finally:
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_consume(requeue_callback,
queue=base_queue+'.error')
channel.start_consuming()
*另外,我可以找到队列中的消息数量,然后使用该特定数量。在那种情况下,我将如何重新排队特定号码。
【问题讨论】:
标签: python queue rabbitmq pika