kafka get partition count for a topic

前端 未结 15 1122
萌比男神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:43

    The number of partitions can be retrieved from zookeeper-shell

    Syntax: ls /brokers/topics//partitions
    

    Below is the example:

    root@zookeeper-01:/opt/kafka_2.11-2.0.0# bin/zookeeper-shell.sh zookeeper-01:2181
    Connecting to zookeeper-01:2181
    Welcome to ZooKeeper!
    JLine support is disabled
    
    WATCHER::
    
    WatchedEvent state:SyncConnected type:None path:null
    ls /brokers/topics/test/partitions
    [0, 1, 2, 3, 4]
    

提交回复
热议问题