Spring Boot Kafka Microservices - #9 - Configure Kafka Topic in OrderService Microservice


Welcome to Spring Boot Kafka Event-Driven Microservices Series. In this lecture, we will Configure Kafka Topic in OrderService Microservice.

Lecture - #9 - Configure Kafka Topic in OrderService Microservice


Source Code - Configure Kafka Topic in OrderService Microservice

In an order-service project, create a config package. Within the config package, create a class named KafkaTopicConfig and add the following configuration to create the Kafka topic.

package net.javaguides.orderservice.config;

import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.TopicBuilder;

@Configuration
public class KafkaTopicConfig {

    @Value("${spring.kafka.topic.name}")
    private String topicName;

    // spring bean for kafka topic
    @Bean
    public NewTopic topic(){
        return TopicBuilder.name(topicName)
                .build();
    }
}


Comments