假设我使用“confirm.select”将通道置于确认模式,并将确认模式设置为手动,然后我执行以下操作(伪代码):
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()
不,
basic.ack
不需要确认。如果确认消息发生问题(例如在网络上丢失),RabbitMQ 会将消息保持在“未确认”状态。当与该消息关联的通道关闭时,RabbitMQ 会将其重新排队并将其传递给该队列的下一个使用者。
请注意,这意味着消息将被传送两次!这是您必须考虑的情况(罕见,但可能)。