0

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

Ag863
  • 27
  • 7

1 Answers1

0

You can't use @RequestBody there - that is a web-only annotation.

Just remove it.

If you are still having problems add the full stack trace to your question.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • thank you:).I was able to move past the failed record moving the offset using one of your answers.I am still having difficulty in setting errorHandlerDeserliazer through application.properties.Can you please point me any implemented examples for that.It would be really hellpful. – Ag863 Jun 14 '21 at 19:43
  • 1
    My answer to this question https://stackoverflow.com/questions/63236346/better-way-of-error-handling-in-kafka-consumer has an example (near the bottom). – Gary Russell Jun 14 '21 at 20:43
  • Thanks alot Gary this gave me a clear picture. – Ag863 Jun 14 '21 at 21:07