Created
September 1, 2017 09:08
-
-
Save starblood/c35a4f70345cbbb5ad20d74d9fbe3f21 to your computer and use it in GitHub Desktop.
find topic and partitions info from ZkUtils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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