You can use the kafka-topics.sh –describe option to know which is the leader for a Kafka topic and the broker instances acting as replicas for the topic, along with the number of partitions of a Kafka Topic that has been created with.
Let’s see a concrete example. First, let’s check which are the available topics:
$ bin/kafka-topics.sh --list --zookeeper localhost:2181 TestTopic myTopic
Now let’s describe the topic “myTopic”:
$ bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic myTopic Topic:myTopic PartitionCount:1 ReplicationFactor:3 Configs: Topic: myTopic Partition: 0 Leader: 1 Replicas: 1,2,0 Isr: 1,2,0
Let’s learn how to read this data:
- Leader: 1 meaning broker instance 1 is responsible for all reads and writes for the given partition. Reads and Writes are done by Kafka Consumers and Kafka Producers respectively.
- Replicas: 1,2,0 meaning broker instances 0, 1 and 2 are acting as nodes that replicate the log irrespective of one being a leader.
- Isr: 1,2,0 meaning broker instances 1, 2 and 0 are in-sync replicas.
Using regular expressions when describing Kafka topics
The option –topic resolves regular expressions, therefore you can use it to return description of multiple Kafka topics with a single command:
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic .*Topic Topic: TestTopic PartitionCount: 1 ReplicationFactor: 1 Configs: Topic: TestTopic Partition: 0 Leader: none Replicas: 0 Isr: 0 Topic: myTopic PartitionCount: 1 ReplicationFactor: 1 Configs: Topic: myTopic Partition: 0 Leader: none Replicas: 0 Isr: 0 Topic: testTopic PartitionCount: 1 ReplicationFactor: 1 Configs: Topic: testTopic Partition: 0 Leader: none Replicas: 0 Isr: 0