Skip to content
Kafka Is FunProgress

SpringSpring Kafka Advanced

How do you implement a batch @KafkaListener in Spring Kafka?

Reference answer

Set spring.kafka.listener.type=BATCH. Your @KafkaListener method accepts List<ConsumerRecord<K,V>> or List<V>. Batch listeners receive a full batch as returned by consumer.poll(). Configure max-poll-records to control batch size. For offset commit with batch: inject Acknowledgment and call ack.acknowledge() after processing the full batch. For individual record error handling within batch, use BatchToRecordAdapter with an appropriate error handler. Batch listeners are more efficient for bulk processing (fewer method invocations, better throughput).

Expected key concepts: spring.kafka.listener.type=BATCH, List<ConsumerRecord>, max-poll-records, Acknowledgment, BatchToRecordAdapter, bulk processing, throughput, consumer.poll, acknowledge