Hello,
I am trying to build a graph modelling a case statement, with the added capability to combine the output of the merge with the input of the partition.
The graph basically looks like this:
+-----------+ +-----------+ +-------+ +-------+ +-----+
| Broadcast |--+-->| Partition |--+-->| Flow1 |--+-->| Merge |--+-->| Zip |
+-----------+ | +-----------+ | +-------+ | +-------+ | +-----+
| | | |
| | +-------+ | |
| +-->| Flow2 |--+ |
| | +-------+ | |
| | | |
| ... |
| | | |
| | +-------+ | |
| +-->| FlowN |--+ |
| +-------+ |
| |
+------------------------------------------------+
It works as I expect it to, as long as Flow1, Flow2, … do not create and merge substreams - in which case the composed flow deadlocks.
The graph is created with:
def when1[A, B, C](partition: A => Int, actions: List[Flow[A, B, NotUsed]], map: (A, B) => C): Flow[A, C, NotUsed] = {
Flow.fromGraph(GraphDSL.create() { implicit builder =>
val b = builder.add(Broadcast[A](2))
val p = builder.add(Partition(actions.size, partition))
val m = builder.add(Merge[B](actions.size))
actions.foreach(p ~> builder.add(_) ~> m)
val agg = builder.add(Flow[(A, B)].map(x => map(x._1, x._2)))
val z = builder.add(Zip[A, B])
b ~> z.in0
b ~> p
m ~> z.in1
z.out ~> agg
FlowShape(b.in, agg.out)
})
}
I want to treat the flows used to parametrize the branches as black boxes. What am I overlooking?
6 posts - 2 participants