This is my config code.
import java.util.function.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.springframework.boot.autoconfigure.kafka.ConcurrentKafkaListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.listener.MessageListenerContainer;
import org.springframework.kafka.listener.SeekToCurrentBatchErrorHandler;
import org.springframework.web.client.RestTemplate;
@Configuration
public class StreamConfiguration {
@Bean
public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(
ConcurrentKafkaListenerContainerFactoryConfigurer factoryConfigure,
ConsumerFactory<Object, Object> kafkaConsumerFactory) {
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
factoryConfigure.configure(factory, kafkaConsumerFactory);
factory.setBatchListener(true);
factory.setBatchErrorHandler(new SeekToCurrentBatchErrorHandler() {
@Override
public void handle(Exception thrownException, ConsumerRecords<?, ?> data, Consumer<?, ?> consumer,
MessageListenerContainer container) {
Config.this.ehException = thrownException;
super.handle(thrownException, data, consumer, container);
}
});
return factory;
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
This is my consumer code
@KafkaListener(id = "#{'${spring.kafka.listener.id}'}", topics = "#{'${spring.kafka.consumer.topic}'}")
public void getTopics(@RequestBody List<Request> model) {
streamProcessor.runParallel(model.parallelStream());
}
I am getting error in handle exception stating that Incorrect number of arguments for type Consumer; it cannot be parameterized with arguments . And i am confused about importing which config to import(Config.this.ehException = thrownException;) as there are two options apache common and apache client admin.
Please help i am not able to set batch error handler and i am in inifinite loop because of deserilization error:(((. I am using Java8