package de.juplo.kafka;
-import org.apache.kafka.clients.consumer.Consumer;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Optional;
-import org.springframework.kafka.core.ConsumerFactory;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import org.springframework.kafka.config.KafkaListenerEndpointRegistry;
@Configuration
kafkaProperties.getClientId());
}
+ @Bean
+ public ApplicationErrorHandler applicationErrorHandler()
+ {
+ return new ApplicationErrorHandler();
+ }
+
@Bean
public EndlessConsumer<String, Message> endlessConsumer(
- Consumer<String, Message> kafkaConsumer,
- ExecutorService executor,
- ApplicationRebalanceListener rebalanceListener,
RecordHandler recordHandler,
+ ApplicationErrorHandler errorHandler,
KafkaProperties kafkaProperties,
- ApplicationProperties applicationProperties)
+ KafkaListenerEndpointRegistry endpointRegistry)
{
return
new EndlessConsumer<>(
- executor,
kafkaProperties.getClientId(),
- applicationProperties.getTopic(),
- kafkaConsumer,
- rebalanceListener,
+ endpointRegistry,
+ errorHandler,
recordHandler);
}
-
- @Bean
- public ExecutorService executor()
- {
- return Executors.newSingleThreadExecutor();
- }
-
- @Bean(destroyMethod = "close")
- public Consumer<String, Message> kafkaConsumer(ConsumerFactory<String, Message> factory)
- {
- return factory.createConsumer();
- }
}