Acknowledgments and prefetch
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
avoid message loss with manual acks.
Planned topics
- Auto-ack removes the message on delivery; a crash during processing loses it.
- Manual ack: acknowledge after the work succeeds;
nackorrejectwith or without requeue on failure. - Unacknowledged messages return to the queue if the consumer dies.
- Prefetch (QoS) limits unacknowledged messages per consumer; it balances load and memory.
- Requeue loops forever on a poison message unless you route it to a dead-letter queue.
- Make handlers idempotent; redelivery is normal.
Draft outline details
Demonstration
@RabbitListener(queues = "email")
void handle(Message m, Channel ch, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
try { process(m); ch.basicAck(tag, false); }
catch (Exception e) { ch.basicNack(tag, false, false); } // no requeue: dead-letter
}Set acknowledge mode manual and prefetch in the listener configuration (verify property names for the Spring Boot version before recording).
Check your understanding
Why is auto-ack risky?
Show answer
The message is removed before the work completes, so a crash loses it.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.