chapter fourteen

14 Alpakka

 

This chapter covers

  • Read and write from and to Kafka
  • Read and write from and to CSV

Alpakka is a project that implements multiple connectors that allow you to interact with different technologies in a reactive streaming way, according to the principles of the Reactive Streams project (https://www.reactive-streams.org). For example, reading from a Kafka topic with an asynchronous stream with no blocking backpressure.

In this chapter you will cover some of the most commonly used connectors, namely Kafka and CSV. The CSV-Alpakka can be classified as finite streams because it ends after the file is read. The Kafka-Alpakka connector, on the other hand, is an example of an infinite stream where there is an open connection to a topic that can produce records at any time.

Alpakka Kafka has an extensive API and most of this chapter is dedicated to it, while the rest is dedicated to CSV which have a relatively simple API.

IMPORTANT

You can use the following code companion to check out the source code of this chapter https://github.com/franciscolopezsancho/akka-topics/tree/main/chapter14. You can find the contents of any snippet or listing in the .scala file with the same name as the class, object or trait.

14.1 Alpakka Kafka

14.1.1 In action

14.1.2 Kafka Consumer

14.1.3 Offset and Consumer Position

14.1.4 Consumer Groups and Topic Subscriptions

14.1.5 Detecting Consumer Failures

14.1.6 Auto commit

14.1.7 Committable source

14.2 Pushing to Kafka

14.2.1 At most Once

14.2.2 At Least Once

14.3 Effectively Once

14.4 Alpakka CSV

14.4.1 Mapping by column

14.4.2 Reading and Writing with FileIO

14.5 Summary