kafka get partition count for a topic

前端 未结 15 1141
萌比男神i
萌比男神i 2020-12-13 00:05

How can I get number of partitions for any kafka topic from the code. I have researched many links but none seem to work.

Mentioning a few:

http://grokbase.c

15条回答
  •  青春惊慌失措
    2020-12-13 00:48

    Go to your kafka/bin directory.

    Then run this:

    ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic topic_name

    You should see what you need under PartitionCount.

    Topic:topic_name        PartitionCount:5        ReplicationFactor:1     Configs:
            Topic: topic_name       Partition: 0    Leader: 1001    Replicas: 1001  Isr: 1001
            Topic: topic_name       Partition: 1    Leader: 1001    Replicas: 1001  Isr: 1001
            Topic: topic_name       Partition: 2    Leader: 1001    Replicas: 1001  Isr: 1001
            Topic: topic_name       Partition: 3    Leader: 1001    Replicas: 1001  Isr: 1001
            Topic: topic_name       Partition: 4    Leader: 1001    Replicas: 1001  Isr: 1001
    

提交回复
热议问题