Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kafka 0.9 - How to create a topic through java api [closed]

New to Kafka.

Having a difficult time figuring out how to use the java-api to create a topic in in the 0.9 release.

This answer deals with 0.8.

I see that the Cluster has methods for querying the partition info, topic, etc. But I can't see how I can dynamically create a topic.

like image 871
hba Avatar asked Dec 17 '15 19:12

hba


1 Answers

For Kafka, the cluster determines how/if you're able to create topics. If you want to be able to create topics on the fly, the easiest way is to use auto.create.topics.enable on your cluster. Then when you send a message to a topic that doesn't exist, the cluster creates the topic with the cluster default partitions and replication factor. If you don't have/want this feature enabled, there are not methods that I know of in the Kafka clients library.

If you're determined, you can look into the internals of the kafka-topics.sh, which is where you'll find how Kafka creates topics with the core api.

Edit
Now Kafka offers Admin API which allows you to programmatically create topics (among other things). See official API docs. (kafka version 1.0.0)

like image 155
David Krieg Avatar answered Sep 28 '22 18:09

David Krieg