假设我将一个通道设置为“confirm.select“的确认模式,并将ack模式设置为手动,然后我执行以下操作(伪代码):
function msg_handler(msg: TheDelivery, chan: TheChannelThatDeliverredThisMessage) {
let new_msg = do_some_computation(msg)
let confirm = chan.basic_publish(some_other_queue, new_msg)
-- wait for rabbitmq to confirm this new_msg
confirm.wait_for_rmq_confirmation()
let x = chan.basic_ack(msg.delivery_tag)
-- Question: do I need x.wait_for_rmq_confirmation() here?
-- namely, does the basic_ack/reject/nack needs to be confirmed
-- if the channel is in confirmation mode?
-- The library I am using doesn't require the ack to be confirmed,
-- for the basic_ack call returns unit, so there is no handle to wait on,
-- I just want to know that this is the way the AMQP designed (no confirms
-- of the ack are generated by the rmq server), or that, the protocol requires
-- that the confirmation of the channel.basic_ack should be generated by the server,
-- it's just that the library I am using that hides this from me (when the channel is
-- in confirmation mode)
}
channel.basic_consume(some_queue_name, msg_handler).wait_forever()
1条答案
按热度按时间ghhaqwfi1#
basic.ack
不需要确认。如果确认消息发生了什么事情(例如,它在网络上丢失),RabbitMQ将保持消息处于“Unacked”状态。当与该消息关联的通道关闭时,RabbitMQ将重新将其入队,并将其传递给该队列的下一个消费者。请注意,这意味着消息 * 将被发送两次!* 这是一个你必须考虑的情况(罕见,但可能)。