1
如何獲得連接Inlet
和Outlet
的實例FlowShape
?考慮下面的例子如何在FlowShape中獲得連接的入口和出口實例?
def throttleFlow[T](rate: FiniteDuration) = Flow.fromGraph(GraphDSL.create() { implicit builder =>
import GraphDSL.Implicits._
val ticker = Source.tick(rate, rate, Unit)
val zip = builder.add(Zip[T, Unit.type])
val map = Flow[(T, Unit.type)].map { case (value, _) => value }
val messageExtractor = builder.add(map)
val in = Inlet[T]("Req.in")
val out = Outlet[T]("Req.out")
out ~> zip.in0
ticker ~> zip.in1
zip.out ~> messageExtractor.in
FlowShape.of(in, messageExtractor.out)
})
,當我在Source.via()
使用它我得到例外
Caused by: java.lang.IllegalArgumentException: requirement failed: The output port [Req.out] is not part of the underlying graph.
at scala.Predef$.require(Predef.scala:219)
at akka.stream.impl.StreamLayout$Module$class.wire(StreamLayout.scala:204)
我缺少的是以下?
啊我看到了。所以返回的FlowShape定義了連接。非常感謝! – expert
僅供參考,它按照預期與Akka 2.4.9編譯和工作。謝謝。 –