Simple Kafka producer in Kotlin, tutorial

Click for: original source

The first in series of tutorials by Alexis Seigneurin focused on Kafka. Author focuses on producing, consuming and processing messages or events.

The tutorial starts by using the Java client library, in particular its Producer API (later down the road, we will see how to use Kafka Streams and Spark Streaming).

It then explains:

  • How to mock source data
  • All about setting up our project
  • The KafkaProducer
  • How to go about testing the code

You will also learn some nice features of the Kotlin language. One thing to keep in mind, when producing data, is what write guarantee you want to achieve.

There is usually a trade-off to be made between your availability to produce, the latency when producing, and the guarantee that your messages will be safely written.

In the tutorial we choose to have a guarantee that a message will be persisted (although not flushed to disk) before we can produce another message: we will not loose messages but our latency is higher than in a “fire and forget” case.

Code examples are also included. Superb!

[Read More]

Tags java programming queues devops kotlin