chapter ten

10 Streams, persistence query and projections

 

This chapter covers

  • How to create a simple stream from its basic components: source, flow and sink
  • How to read the events from journal of the persistence entities
  • How to read the events from journal of the persistence entities and write them into another table, so you can optimize a specific query

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

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.

There are a few problems when you interact with live events or a constant flow of information. These are infinite by definition, so you can't wait until the process is finished to process its contents. Some others, like audio, are usually not infinite, but you don't want to wait until the whole song or video is transferred to play it?

10.1.1 Basic semantics

10.1.2 Finite Streams

10.1.3 Source

10.1.4 Flow

10.1.5 Sink

10.1.6 Blueprint

10.1.7 Materialization

10.1.8 Infinite streams

10.2 Akka persistence query

10.2.1 Where the rubber meets the road

10.3 Projections

10.3.1 Reading

10.3.2 Writing

10.3.3 Put everything together

10.3.4 Tangent on ShardedDaemonProcess

10.3.5 Back to SPContainer projection

10.3.6 All the Main parts

10.4 Projections in Action

10.5 Summary