Custom stream processing
Sometimes, all the out-of-the-box Akka Streams stages do not cover a specific scenario you need. Akka Streams provides a set of APIs to create your own custom stage. Since Streams are essentially processing graphs, to create a custom stage, you need to extend the GraphStage
abstraction. Let's not confuse GraphDSL
with GraphStage
. The main difference between GraphDSL
, which is used to compose multiple stages into a single stage, and GraphStage
is that the latter cannot be decomposed into smaller pieces.
At this point, we need to learn a bit about how Akka Streams works internally. To begin with, there is the concept of shape. A shape defines the number of input and output ports in your stage (known as inlets and outlets). For example, SourceShape
has only one outlet. A SinkShape
has one inlet. A FlowShape
has one inlet and one outlet. It is also possible to have an AmorphousShape
, which has an arbitrary number of inlets and outlets. Every GraphStage
also encompasses...