I am trying to create a topic in kafka 0.8.2 by using :
AdminUtils.createTopic(zkClient, myTopic, 2, 1, properties);
If I run the code more than once locally for testing, this fails as the topic was already created. Is there a way to check if the topic exists before creating the topic? The TopicCommand
api doesn't seem to return anything for listTopics
or describeTopic
.
You can use AdminClient from kakfa-client version 0.11.0.0
Sample code:
For this purpose, you can use the method
AdminUtils.topicExists(ZkUtils zkClient, String topic)
, it will returntrue
if the topic already exists,false
otherwise.Your code would then be something like this: