10 Streams, persistence query, and projections
This chapter covers
- Creating a simple stream from its basic components: source, flow and sink
- Reading the events from journal of the persistence entities
- Writing the events from journal into another table
In this chapter you will learn how to read from the journal and create views from it. To do this, Akka uses Akka Streams explicitly to read the journal - with the persistence-query module - and implicitly to create views - with the projections module.
IMPORTANT
You can use the following code companion https://github.com/franciscolopezsancho/akka-topics/tree/main/chapter10a to check out the source code for the following examples. You can find the contents of any snippet or listing in the .scala file with the same name as the class, object or trait.
10.1 Akka Streams
A stream is a sequence of data. It can be infinite, but it doesn't have to be. Examples include the messages you send or receive via email, the tweets posted each day, the clicks you make on a website, or the videos you watch. From the perspective of the application that processes all of these events, it's clear that in some cases it's a huge amount of interaction.