kafka获取主题的分区计数 [英] kafka get partition count for a topic
问题描述
如何从代码中获取任何kafka主题的分区数。我研究了许多链接,但似乎都没有。
How can I get number of partitions for any kafka topic from the code. I have researched many links but none seem to work.
提到一些:
http://grokbase.com/t/kafka/users/148132gdzk/find-topic -partition-count-through-simpleclient-api
http://grokbase.com/t/kafka/users/151cv3htga/get-replication-and-partition-count-of-a-topic
http://qnalist.com/questions/5809219/get-replication-and-partition-count-of-a-topic
看起来像类似的讨论。
此外,SO上也有类似的链接,但没有可行的解决方案。
Also there are similar links on SO which do not have a working solution to this.
推荐答案
转到 kafka / bin
目录。
然后运行:
./ kafka-topics.sh --describe --zookeeper localhost:2181 - topic topic_name
你应该在 PartitionCount $ c下看到你需要的东西$ C>。
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
这篇关于kafka获取主题的分区计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!