SpringSpring Kafka Configuration
How do you set up manual offset commits in Spring Kafka?
Reference answer
Set spring.kafka.listener.ack-mode=MANUAL or MANUAL_IMMEDIATE. Inject Acknowledgment in the @KafkaListener method: @KafkaListener ... public void listen(ConsumerRecord<K,V> record, Acknowledgment ack). After processing: ack.acknowledge() (MANUAL: batch commit at next poll) or ack.acknowledge() with MANUAL_IMMEDIATE (commit immediately). For batch listeners, acknowledge after processing the entire batch. MANUAL_IMMEDIATE causes a network round-trip per batch — use MANUAL for throughput-sensitive scenarios.
Expected key concepts: spring.kafka.listener.ack-mode, MANUAL, MANUAL_IMMEDIATE, Acknowledgment, ack.acknowledge, batch, network round-trip, ConsumerRecord, @KafkaListener