我需要循環回調隊列中的所有消息,然後關閉回調。我需要它在隊列清空後停止使用。 因此,我正在將消息從一個隊列寫入另一個隊列。使用pika將所有消息從一個隊列重新排列到另一個隊列
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()
*另外,我能找到一個隊列的消息的數量,然後消費該具體數目。在那種情況下,我將如何重新排列特定的號碼。