Skip to content

6. OrderService Microservice Configure Kafka Topic

Ramesh Fadatare edited this page Jul 11, 2022 · 1 revision

Create Kafka Topic while application startup

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;

    @Bean
    public NewTopic javaguidesTopic(){
        return TopicBuilder.name(topicName)
                .build();
    }
}