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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With