Simple Kafka Utils in Scala
- simple api
- see
sc.ala.kafka.utils.Api
- see
import sc.ala.kafka.utils._
val utils = KafkaUtils("localhost:2181") // set zkConnect
utils.brokers
// Seq[kafka.cluster.Broker] = ArrayBuffer(id:1,host:ubuntu,port:9092)
utils.topics
// Seq[String] = ArrayBuffer(topic1, test)
utils.create("topic1", 1, 3)
utils.leaders("topic1")
// Map[Int,Option[Int]] = Map(2 -> Some(1), 1 -> Some(1), 0 -> Some(1))
utils.partitions("topic1")
// Seq[Int] = ArrayBuffer(2, 1, 0)
utils.delete("topic1")
utils.count("topic1")
// Long = 5
utils.counts("topic1")
// Map(2 -> 0, 1 -> 5, 0 -> 0)
utils.topics.sorted.foreach{ t => println(s"${utils.count(t)}\t$t") }
// 1 t1
// 1534339 t2
// 0 t3
utils.offset("topic1")
// Long = 5
utils.offsets("topic1")
// Map[Int,Long] = Map(2 -> 0, 1 -> 0, 0 -> 3)
utils.close
- write tests
- consumers
- kafka-0.9.0
- kafka-0.8.2