【发布时间】:2017-08-06 09:41:58
【问题描述】:
从我的生产者代码中,我想知道消费者何时收到basic.acked 消息。
使用 channel.confirm_delivery() 和 BlockingConnection 从文档中不清楚这是否应确认 1) 代理已收到消息,或 2) 消费者已确认收到消息。
运行此代码(没有消费者):
import pika
import uuid
# Open a connection to RabbitMQ on localhost using all default parameters
connection = pika.BlockingConnection()
# Open the channel
channel = connection.channel()
queue = str(uuid.uuid4())
# Declare the queue
channel.queue_declare(queue=queue)
# Turn on delivery confirmations
channel.confirm_delivery()
# Send a message
if channel.basic_publish(exchange='',
routing_key=queue,
body='Hello World!',
properties=pika.BasicProperties(
content_type='text/plain',
delivery_mode=1)):
print('Message publish was confirmed')
else:
print('Message could not be confirmed')
显示要确认的消息。这不是我所期望或想要的。
这可能与 Behavior of channels in "confirm" mode with RabbitMQ 但是basic_publish 的文档说
:返回:如果未启用交货确认,则返回 True(pika 中的新 0.10.0);否则返回 False 如果消息不能 已交付(Basic.nack 和/或 Basic.Return)如果消息为 True 已交付(Basic.ack 且没有 Basic.Return)
这让我觉得它应该首先拥有我想要的。
【问题讨论】: