Created
September 24, 2018 09:45
-
-
Save adekunleba/2ba54936ed953d36c0d86369a691052d to your computer and use it in GitHub Desktop.
Some Utility Function for programming Kafka in Scala
This file contains hidden or 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
| //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