Skip to content

Instantly share code, notes, and snippets.

@starblood
Created September 1, 2017 09:08
Show Gist options
  • Save starblood/c35a4f70345cbbb5ad20d74d9fbe3f21 to your computer and use it in GitHub Desktop.
Save starblood/c35a4f70345cbbb5ad20d74d9fbe3f21 to your computer and use it in GitHub Desktop.
find topic and partitions info from ZkUtils
import kafka.utils.ZkUtils
object KafkaTopicTest {
def createZkUtils(): ZkUtils = {
val zookeepers = "localhost:2181"
val timeout = 10000
ZkUtils(zookeepers, timeout, timeout, isZkSecurityEnabled = false)
}
def getPartitionsForTopics(topics: Seq[String]): Map[String, Seq[Int]] = {
zkUtils.getPartitionsForTopics(topics).toMap
}
def getPartitionsForTopic(topic: String): Option[Seq[Int]] = {
zkUtils.getPartitionsForTopics(Seq(topic)).get(topic)
}
def main(args: Array[String]): Unit = {
val topicName = args(0)
val topicAndPartitionMap = getPartitionsForTopic(topicName)
println(topicAndPartitionMap)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment