Checking if a theme exists in kafka before building in Java

I am trying to create a theme in kafka 0.8.2 using:

        AdminUtils.createTopic(zkClient, myTopic, 2, 1,properties);

      

If I run the code more than once locally for testing, it fails because the theme has already been created. Is there a way to check if a theme exists before creating a theme? TopicCommand

api doesn't seem to return anything for listTopics

or describeTopic

.

+3


source to share


1 answer


I would say



if(!AdminUtils.topicExists(zkClient, myTopic)){
    AdminUtils.createTopic(zkClient, myTopic, 2, 1,properties);
}

      

+3


source







All Articles