I am creating a spring-boot application which will create multiple topics. I am taking the list of topic names and configurations from a .csv file. I am trying this code but it can only create a single topic but its not favorable to create multiple topics using this. Is there a way to create multiple topics using spring?
@Bean
public KafkaAdmin admin(){
Map<String, Object> configs = new HashMap<>();
configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,"localhost:9092");
return new KafkaAdmin(configs);
}
@Bean
public NewTopic topic1() {
NewTopic topic = new NewTopic(String.format("topic%d",1), 10, (short) 1);
Map<String, String> extraTopicConfig = new HashMap<String, String>();
extraTopicConfig.put(TopicConfig.CLEANUP_POLICY_CONFIG, "compact");
extraTopicConfig.put(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "1");
topic.configs(extraTopicConfig);
return topic;
}