Home > Enterprise >  Make Kafka topics be created automatically from spring boot
Make Kafka topics be created automatically from spring boot

Time:10-16

My Spring boot project has 4 modules and I needed to use Kafka to establish communication between the modules. I installed Kafka on my computer and created the topics using cmd.

The problem is, after I submit my project, the topics won't work unless my teacher has the same topics created on his computer (from what I understand).

Is there a way to make sure my project automatically creates the topics?

CodePudding user response:

Yes, you can use spring-kafka dependency and add some Topic beans

@Bean
public NewTopic topic() {
  return TopicBuilder.name("example")....build();
}

https://docs.spring.io/spring-kafka/reference/html/#configuring-topics

  • Related