Vagif Abilov
Vagif Abilov

Reputation: 9991

Why does an Akka stream has exactly one source and sink?

Akka Streams docs clearly state that in order for a stream to be runnable it must have exactly one source and exactly one sink. I wonder what imposes such constraint. Scenarios with multiple sources merged into one multiple sinks forked from a single stream are all very reasonable. Are there any technical reasons back such restriction?

Upvotes: 2

Views: 216

Answers (1)

Stefano Bonetti
Stefano Bonetti

Reputation: 9023

I am going to assume you refer to this documentation section, which defines the fundamental components of Akka Streams:

Source: A processing stage with exactly one output, [...]

Sink: A processing stage with exactly one input, [...]

Flow: A processing stage which has exactly one input and output, [...]

RunnableGraph: A Flow that has both ends "attached" to a Source and Sink respectively, and is ready to be run().

Now whereas the first 3 definitions are clear and truthful, I think the definition of RunnableGraph is incomplete. A RunnableGraph can be defined as described (i.e. source.via(flow).to(sink)), and this is the simplest way you can get one of those. However, there are more flexible and complex ways to define RunnableGraphs, for example the GraphDSL.

If you check out the examples in this section, you'll see RunnableGraphs built up from multiple sources and/or multiple sinks.

It's probably more accurate to say that a RunnableGraph is a processing stage with no inputs and no outputs (i.e. has a ClosedShape).

Upvotes: 2

Related Questions