Search code examples
springapache-kafkaspring-kafka

Spring Kafka Property for setting SeekToCurrentBatchErrorHandler


Is there a spring.kafka property error handling batches

spring.kafka.listener.type=BATCH and spring.kafka.listener.ack-mode=BATCH

with SeekToCurrentBatchErrorHandler ? Thanks in advance.


Solution

  • You cannot set it with a property, but you can override Boot's auto-configured container factory like so:

    @Bean
    public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(
            ConcurrentKafkaListenerContainerFactoryConfigurer configurer,
            ConsumerFactory<Object, Object> kafkaConsumerFactory) {
    
        ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
        configurer.configure(factory, kafkaConsumerFactory);
    
        factory.setBatchErrorHandler(new SeekToCurrentBatchErrorHandler());
    
        return factory;
    }
    

    It will get all the boot properties and you can then further configure the factory as needed.