I am using kafka 0.8
version and very much new to it.
I want to know the list of topics created in kafka server
along with it's
metadata.
Is there any API available to find out this?
Basically, I need to write a Java consumer that should auto-discover any topic in kafka server
.There is API to fetch TopicMetadata
, but this needs name of topic as input
parameters.I need information for all topics present in server.
I think this is the best way:
Using Scala:
with Kafka 0.9.0
you can list the topics in the server with the provided consumer method listTopics();
eg.
You can use zookeeper API to get the list of brokers as mentioned below:
Use this broker list to get all the topic using the following link
https://cwiki.apache.org/confluence/display/KAFKA/Finding+Topic+and+Partition+Leader
If you want to pull broker or other-kafka information from Zookeeper then
kafka.utils.ZkUtils
provides a nice interface. Here is the code I have to list all zookeeper brokers (there are a ton of other methods there):A good place to start would be the sample shell scripts shipped with Kafka. In the /bin directory of the distribution there's some shell scripts you can use, one of which is ./kafka-topic-list.sh If you run that without specifying a topic, it will return all topics with their metadata. See: https://github.com/apache/kafka/blob/0.8/bin/kafka-list-topic.sh
That shell script in turn runs: https://github.com/apache/kafka/blob/0.8/core/src/main/scala/kafka/admin/ListTopicCommand.scala
The above are both references to the 0.8 Kafka version, so if you're using a different version (even a point difference), be sure to use the appropriate branch/tag on github