kafka获取主题的分区计数 [英] kafka get partition count for a topic

查看:140
本文介绍了kafka获取主题的分区计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从代码中获取任何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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆