Self-Learning Kafka Streams with Scala — #1

Knoldus Inc.
Jul 22, 2017 · 2 min read

A few days ago, I came across a situation where I wanted to do a stateful operation on the streaming data. So, I started finding possible solutions for it. I came across many solutions which were using different technologies like Spark Structured Streaming, Apache Flink, Kafka Streams, etc.

All the solutions solved my problem, but I selected Kafka Streams because it met most of my requirements. After that, I started reading its documentation and trying to run its examples. But, as soon as I started learning it, I hit a major roadblock, that was, “Kafka Streams does not provide a Scala API!”. I was shocked to know that.

The reason I was expecting Kafka Streams to have a Scala API was that I am using Scala to build my application and if Kafka Streams provided an API for it then it would have been easy for me to include it in my application. But that didn’t turn out to be the case. Over the top when I searched for its Scala examples, I was able to find only a handful of them.

So, I decided to learn it on my own and my first step was to build a “Hello World!” program using Kafka Streams and Scala, like this:

Before running this example, we need to start Kafka server. To do that you can read their quick start guide. After that, send some messages to Kafka topic — “SourceTopic” and start a Kafka Consumer for Kafka topic — “SinkTopic”.

[code language=”bash”]
$ bin/kafka-console-producer.sh — broker-list localhost:9092 — topic SourceTopic
hello world!
[/code]

Now, run the example and you will see that Kafka consumer topic — “SinkTopic” will receive the message.

[code language=”bash”]
$ bin/kafka-console-consumer.sh — bootstrap-server localhost:9092 — topic SinkTopic
hello world!
[/code]

This means that now we are able to send messages from one Kafka topic to another via Kafka Streams.

So, this was my first step to learn Kafka Streams with Scala. I know that it is not much, but I still need to explore more in Kafka Streams like transformations, joins, aggregations, etc., about which I will be writing in my future posts. So, stay tuned :)

The complete code can be downloaded from Github.

Please feel free to suggest or comment!


knoldus-advt-sticker
knoldus-advt-sticker

Knoldus - Technical Insights

Knols, Insights and Opinions from the curious minds at Knoldus Inc.

Knoldus Inc.

Written by

Group of smart Engineers with a Product mindset who partner with your business to drive competitive advantage | www.knoldus.com

Knoldus - Technical Insights

Knols, Insights and Opinions from the curious minds at Knoldus Inc.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade