Akka蒸汽中FanOut形状的大多数示例要么将淡出的流合并为单个流,要么立即将它们连接到接收器。我希望返回一系列Source,然后我可以应用转换并稍后连接到接收器。一个例子看起来像这样
def transformedSources(src: Source[Int,NotUsed]) : Seq[Source[Int,NotUsed]] {
import GraphDSL.Implicits._
val builder = new GraphDSL.Builder
val bcast = builder.add(Broadcast[Int](2))
src.out ~> bcast.in
val sourceShapes = (bcast.out).map { out => SourceShape(out)}}
??? // How to convert sourceShapes into Sources
}
有没有办法实现这个目标?
P.S 我的真实用例是AmorphousShape,它接受X源,并产生X输出。理想情况下,我想应用AmorphousShape阶段,然后继续运行,好像什么都没有改变。 所以如果我现在的代码是
sources.map{s => s.via(someStage).runWith(Sink.seq)}
我想将其转换为
transformSource(sources).map{s => s.via(someStage).runWith(Sink.seq)}
def transformSource(sources:Seq[Source[Int, NotUsed]]) : Seq[Source[Int, NotUsed]] = {do some magic with an AmorphousShape graph }