Source, Flow, and Sink
The streaming building blocks.
The Three Building Blocks
Akka Streams models a data pipeline as a graph of processing stages. The three core linear stages are Source (produces elements), Flow (transforms them), and Sink (consumes them).
A Source has one output, a Sink has one input, and a Flow has exactly one input and one output. Wiring them together describes what should happen, not when.
Defining a Source
A Source[Out, Mat] emits elements of type Out and exposes a materialized value of type Mat. The simplest sources come from in-memory collections or ranges.
Until the stream is run, a Source is just an immutable blueprint that can be reused freely.
import akka.stream.scaladsl.Source
val numbers: Source[Int, akka.NotUsed] =
Source(1 to 100)
val single: Source[String, akka.NotUsed] =
Source.single("hello")All lessons in this course
- Source, Flow, and Sink
- Transforming Streams
- Backpressure
- Running a Pipeline