Skip to content

Instantly share code, notes, and snippets.

@adekunleba
Created September 24, 2018 09:45
Show Gist options
  • Select an option

  • Save adekunleba/2ba54936ed953d36c0d86369a691052d to your computer and use it in GitHub Desktop.

Select an option

Save adekunleba/2ba54936ed953d36c0d86369a691052d to your computer and use it in GitHub Desktop.
Some Utility Function for programming Kafka in Scala
//Create new Kafka topic
def createTopic(topic: String, client: AdminClient) = {
val newTopic = new NewTopic(topic, 6, 3.toShort)
try {
val topic = client.createTopics(List(newTopic).asJavaCollection)
topic.values().get(topic).get() //Not Scala design here
} catch {
case e: InterruptedException with ExecutionException=> {
case d: TopicExistsException => throw new RuntimeException(e.getMessage, e)
case _ => println(s"$topic you are trying to create already exists")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment