我一直在尝试使用Akka Streams,产生了创建Flows并使用FlowGraphs将它们连接在一起的想法。
我知道Akka的这一部分仍在开发中,所以有些事情可能还没有完成,一些其他的部分可能会改变,但有没有可能创建一个不“完整”的FlowGraph --也就是没有附加到Sink上--并将它传递到我的代码的不同部分,通过添加流来扩展它,最后通过添加Sink来完成呢?
基本上,我希望能够编写FlowGraphs,但不明白如何...特别是如果FlowGraph已经通过使用广播分割了流。
谢谢
发布于 2014-12-07 08:32:08
下周(12月)将为我们编写文档,所以我希望这将帮助您更容易地进入akka streams!话虽如此,这里有一个快速的答案:
基本上,您需要的是PartialFlowGraph而不是FlowGraph。在这些文件中,我们允许使用UndefinedSink和UndefinedSource,然后您可以“附加”它们。在你的例子中,我们还提供了一个简单的助手构建器来创建恰好有一个“缺失”接收器的图-这些接收器可以被完全视为一个源,如下所示:
// for akka-streams 1.0-M1
val source = Source() { implicit b ⇒
// prepare an undefined sink, which can be relpaced by a proper sink afterwards
val sink = UndefinedSink[Int]
// build your processing graph
Source(1 to 10) ~> sink
// return the undefined sink which you mean to "fill in" afterwards
sink
}
// use the partial graph (source) multiple times, each time with a different sink
source.runWith(Sink.ignore)
source.runWith(Sink.foreach(x ⇒ println(x)))希望这能有所帮助!
https://stackoverflow.com/questions/27337646
复制相似问题