I am using below code snippet to create topic in multiple zookeepers with Kafka Java APIS. when I specify 2 zookeeprs IPs in zookeeperConnect variable it only creates topic in anyone of zookeeper. Both the zookeeper are 2 different kafka cluster. Any Help ?
String zookeeperConnect = zookeeperIPs; // Multiple zookeeper IPs
int sessionTimeoutMs = 10 * 1000;
int connectionTimeoutMs = 8 * 1000;
try {
ZkClient zkClient = new ZkClient(
zookeeperConnect,
sessionTimeoutMs,
connectionTimeoutMs,
ZKStringSerializer$.MODULE$);
boolean isSecureKafkaCluster = false;
ZkUtils zkUtils = new ZkUtils(zkClient,
new ZkConnection(zookeeperConnect), isSecureKafkaCluster);
String topic1 = "nameofTopictobeCreated";
int partitions = 1;
int replication = 1;
Properties topicConfig = new Properties(); // add per-topic configurations settings here
AdminUtils.createTopic(zkUtils, topic1, partitions, replication, topicConfig);
答案 0 :(得分:0)
工具AdminUtils
假定all指定ZK属于同一个集群,因此与其中一个集合通信就足够了(因为ZK节点将自动同步)。
如果要在两个群集中创建主题,则需要两次发出命令,每次使用不同的ZK节点。