1

I've been playing around with Akka Streams and get the idea of creating Flows and wiring them together using FlowGraphs.

I know this part of Akka is still under development so some things may not be finished and some other bits may change, but is it possible to create a FlowGraph that isn't "complete" - i.e. isn't attached to a Sink - and pass it around to different parts of my code to be extended by adding Flow's to it and finally completed by adding a Sink?

Basically, I'd like to be able to compose FlowGraphs but don't understand how... Especially if a FlowGraph has split a stream by using a Broadcast.

Thanks

4

1 回答 1

0

下周(12 月)将为我们编写文档,所以我希望这能帮助您更轻松地进入 akka 流!话虽如此,这里有一个快速的答案:

基本上你需要 aPartialFlowGraph而不是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)))

希望这可以帮助!

于 2014-12-07T00:32:07.530 回答