Count
Count

Reputation: 1423

Exception when creating kafka topic through java

I am trying to create a kafka topic via AdminCommand using below code Source

 ZkClient zkClient = new ZkClient(kafkaHost, 10000, 10000, ZKStringSerializer$.MODULE$);
    AdminUtils.createTopic(zkClient, "pa_reliancepoc_telecom_usageevent", 10, 1, new Properties());

But getting the below exception

Exception in thread "main" org.I0Itec.zkclient.exception.ZkNoNodeException: org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /brokers/ids
at org.I0Itec.zkclient.exception.ZkException.create(ZkException.java:47)
at org.I0Itec.zkclient.ZkClient.retryUntilConnected(ZkClient.java:685)

Upvotes: 2

Views: 1122

Answers (1)

Jaya Ananthram
Jaya Ananthram

Reputation: 3463

From your exception, It says it could not able to connect zookeeper. In your code,

ZkClient zkClient = new ZkClient(kafkaHost, 10000, 10000, ZKStringSerializer$.MODULE$); 

The first argument is the zookeeper host, I don't know what you are having in the kafkaHost variable, As the name implies I think you have stored kafka host in that variable. Change the first argument by giving the zookeeper host. For example,

String zkHosts = "xxx.xxx.xx.xx:2181";
ZkClient zkClient = new ZkClient(zkHosts, 10000, 10000, ZKStringSerializer$.MODULE$); 

If you are having more then one zookeeper then give as comma separated string. For example,

String zkHosts = "xxx.xxx.xx.xx:2181,yyy.yyy.yy.yy:2181";

Upvotes: 1

Related Questions