确认(acks) 告诉 RabbitMQ 消息已成功处理,以便可以从队列中删除。它们对于 可靠交付 至关重要——确保如果消费者失败消息不会丢失。
确认如何工作
When a consumer receives and processes a message, it ACKNOWLEDGES it:
→ ACK → "I've processed this message" → RabbitMQ removes it from the queue
→ if a consumer DIES before acking (crash, disconnect) → RabbitMQ REQUEUES the message
→ redelivered to another consumer (NOT lost)
→ acks ensure messages are processed reliably (not lost if a consumer fails)
手动与自动确认
MANUAL ack → the consumer explicitly acks AFTER processing → reliable (message redelivered
if processing fails) — the safe choice for important messages
AUTOMATIC ack → the message is considered acked as soon as it's DELIVERED (before processing)
→ faster but UNSAFE → if the consumer crashes during processing, the message is LOST
→ use MANUAL acks for reliability (ack only after successful processing)
