How to start Spring Kafka Application with Spring Boot
The Spring Apache Kafka (spring-kafka) provides a high-level abstraction for Kafka-based messaging solutions. And in the previous post, We had developed a Spring Kafka Application with the auto-configuration supported by SpringBoot (from version 1.5). But when we need explicitly configure Kafka factories (Kafka Producer and Kafka Consumer) for development, how to do it? So in the tutorial, JavaSampleApproach will introduce an alternative solution by manually configure Kafka factories to build a Spring Kafka Application.
Related Articles:
We will explicitly implement a ProducerFactory and ConsumerFactory with customized properties:
@Bean
public ProducerFactory producerFactory() {
Map configProps = new HashMap<>();
...
return new DefaultKafkaProducerFactory<>(configProps);
}
@Bean
public ConsumerFactory consumerFactory() {
Map props = new HashMap<>();
...
return new DefaultKafkaConsumerFactory<>(props);
}
Then use ProducerFactory to build KafkaTemplate and use ConsumerFactory to build
ConcurrentKafkaListenerContainerFactory which will handle @KafkaListener
later:
More at:
How to start Spring Kafka Application with Spring Boot
#springboot #activemq #spring-kafka #kafka