How it works...
In this recipe, we demonstrated how to produce and consume records from an Apache Kafka topic. Apache Kafka uses a Key-Value approach to deal with data. This Key-Value pair helps you distribute your records among all the available partitions in the Kafka cluster. Keys and Values need to be serialized and deserialized. For this purpose, Apache Kafka provides a set of predefined serializers and deserializers. In our case, we used Array[Byte] for Key and String for Value.
First, we produced data to the topic. For this purpose, we used Source.tick that emits a string element periodically. These string elements were then mapped to ProducerRecord objects. ProducerRecord is the type a producer understands to push data to the Apache ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access