79362590

Date: 2025-01-16 17:47:21
Score: 1
Natty:
Report link

If you define a KafkaAdmin bean in your application context, it can automatically add topics to the broker. To do so, you can add a NewTopic @Bean for each topic to the application context. Add the following code snippet that can use the same configuration to create the topic and kafka template also use the same

@Bean public KafkaAdmin admin() {
Map<String, Object> configs = new HashMap<>();
configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
return new KafkaAdmin(configs);

}

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Bean
  • Low reputation (1):
Posted by: Shahid Hussain