pika confirm_delivery 是 broker 收到消息还是 consumer 确认的意思?
Does pika confirm_delivery mean confirm when broker got the message or when consumer acknowledged?
从我的生产者代码中,我想知道消费者何时 basic.ack
发送了一条消息。
使用 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 however the documentation for basic_publish 说
:returns: True if delivery confirmation is not enabled (NEW in pika
0.10.0); otherwise returns False if the message could not be
deliveved (Basic.nack and/or Basic.Return) and True if the message
was delivered (Basic.ack and no Basic.Return)
这让我觉得它首先应该有我想要的。
confirm_deliveries
只是意味着当 RabbitMQ 收到消息时,basic.ack(收到消息)或 basic.nack(未收到消息收到)将被退回。
但这并不能保证邮件已成功传递到队列。您将需要为不可路由的消息添加强制标志以抛出异常。
您可以阅读有关确认交付和强制标记的更多信息 here。
回答您的问题;发布者无法知道消费者是否成功处理了消息。但是,如果一个消费者消费消息失败,它应该重新排队并由另一个消费者处理,但这取决于消费者的设计情况。
如果您确实需要知道一条消息是否已得到正确处理,那么实施类似 RPC 调用的方式来回复请求的状态可能是最好的方法。如果您在 X 秒内没有得到响应,则假定该消息未得到处理。
https://www.rabbitmq.com/tutorials/tutorial-six-python.html
如果您需要 rpc 发布者的异步示例,您可以查看我的一些 flask 示例 here。
从我的生产者代码中,我想知道消费者何时 basic.ack
发送了一条消息。
使用 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 however the documentation for basic_publish 说
:returns: True if delivery confirmation is not enabled (NEW in pika 0.10.0); otherwise returns False if the message could not be deliveved (Basic.nack and/or Basic.Return) and True if the message was delivered (Basic.ack and no Basic.Return)
这让我觉得它首先应该有我想要的。
confirm_deliveries
只是意味着当 RabbitMQ 收到消息时,basic.ack(收到消息)或 basic.nack(未收到消息收到)将被退回。
但这并不能保证邮件已成功传递到队列。您将需要为不可路由的消息添加强制标志以抛出异常。
您可以阅读有关确认交付和强制标记的更多信息 here。
回答您的问题;发布者无法知道消费者是否成功处理了消息。但是,如果一个消费者消费消息失败,它应该重新排队并由另一个消费者处理,但这取决于消费者的设计情况。
如果您确实需要知道一条消息是否已得到正确处理,那么实施类似 RPC 调用的方式来回复请求的状态可能是最好的方法。如果您在 X 秒内没有得到响应,则假定该消息未得到处理。 https://www.rabbitmq.com/tutorials/tutorial-six-python.html
如果您需要 rpc 发布者的异步示例,您可以查看我的一些 flask 示例 here。