I just started to use spring-kafka 2.6.4. I created consumer factory that polls messages by batches:
@Bean
public ConcurrentKafkaListenerContainerFactory<String, String>
kafkaListenerContainerFactory(MeterRegistry meterRegistry) {
ConcurrentKafkaListenerContainerFactory<String, String> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
factory.setConcurrency(kafkaProperties.getTopicConcurrency());
factory.setBatchListener(true);
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.BATCH);
return factory;
}
Now I want to define proper error handler that causes the consumer to stuck on the failed record and not to poll the next batch.
Which error handler should I use?
Thanks.
The RecoveringBatchErrorHandler (https://docs.spring.io/spring-kafka/docs/current/reference/html/#recovering-batch-eh) is now the preferred (and default since 2.5) batch error handler. Your listener can throw a specific exception to indicate which record in the batch failed.
There is also a RetryingBatchErrorHandler (https://docs.spring.io/spring-kafka/docs/current/reference/html/#retrying-batch-eh).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With