Kafka - java to scala - introduction

Posted: 2019-04-25 / Updated: 2020-01-23

I was recently a participant on a Confluent on-premesis kafka course. While working through the labs (which are in java), for fun I tried the same code in kotlin. That was fun - but I thought it could be a nice exercise to convert from java to scala - step by step - and maybe learn some new scala stuff on the way. It will assume some level of kafka knowledge - what is a producer, consumer, topic etc.

It is important to understand that it is written from my viewpoint - someone who has played with scala, likes it, but has never really had time to get into it - so this will be somewhat of a discovery journey for me too.

Posts in this series

  1. A simple java example running - a basic producer and consumer pair
  2. Convert java to scala - conversion of the basic producer and consumer to scala - on an almost line by line basis
  3. Update the scala version to be more "scala-like" and add a config file instead of hard coded values
  4. A slight digression to look at basic akka-streams
  5. Use akka-streams for the scala example

Code

All code is available in this github repository: https://github.com/chrissearle/kafka-java-to-scala

Docker

All of the related articles assume that you have kafka running using the supplied docker-compose.yml file - so in the working directory - run:

docker-compose up

Make sure you have a good amount of memory available to docker - 4-5 Gb minimum :)