All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.keyko.monitoring.preprocessing.TopicCreation Maven / Gradle / Ivy

There is a newer version: 0.2.9
Show newest version
package io.keyko.monitoring.preprocessing;

import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.NewTopic;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class TopicCreation {

  public static void createTopics(List topicNames, String kafkaServer) {
    Properties props = new Properties();
    props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaServer);
    AdminClient a = AdminClient.create(props);
    a.createTopics(convertToNewTopics(topicNames));
  }

  public static List convertToNewTopics(List topicNames) {
    List topics = new ArrayList();
    for (String i : topicNames) {
      topics.add(new NewTopic(i, 1, (short) 1));
    }
    return topics;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy