我收到了可怕的java.lang.IllegalArgumentException: requirement failed: The inlets [] and outlets [] must correspond to the inlets [Map.in] and outlets []
错误消息,以前的SO答案对我没有帮助。
这是我的图表
val graph = RunnableGraph.fromGraph(GraphDSL.create(sink){ implicit b =>
s =>
import GraphDSL.Implicits._
val broadcast = b.add(Broadcast[Foo](2))
val merge = b.add(Merge[Foo](2))
source ~> func1() ~> broadcast.in
broadcast.out(0).filter(_.country == "US") ~> usSpecificFilter ~> merge.in(0)
broadcast.out(1).filter(_.country != "US") ~> internationalFilter ~> merge.in(1)
merge.out ~> sink
ClosedShape
})
def func1() : Flow[String, Foo, NotUsed] = {...}
从以前的线程我可以收集到,如果你有“未使用的流”(意味着添加到构建器但未在图中使用的东西),则会出现此错误。
但正如您在上面所看到的那样,我没有未使用过的流量。
编辑::
val graph = RunnableGraph.fromGraph(GraphDSL.create(sink){ implicit b =>
s =>
import GraphDSL.Implicits._
val broadcast = b.add(Broadcast[Foo](2))
val merge = b.add(Merge[Foo](2))
val s = b.add(sink)
source ~> func1() ~> broadcast.in
broadcast.out(0).filter(_.country == "US") ~> usSpecificFilter ~> merge.in(0)
broadcast.out(1).filter(_.country != "US") ~> internationalFilter ~> merge.in(1)
merge.out ~> s.in
ClosedShape
})
仍然无效!
答案 0 :(得分:2)
在图表中,将merge.out ~> sink
更改为merge.out ~> s.in
:
val graph = RunnableGraph.fromGraph(GraphDSL.create(sink) { implicit b => s =>
import GraphDSL.Implicits._
val broadcast = b.add(Broadcast[Foo](2))
val merge = b.add(Merge[Foo](2))
source ~> func1() ~> broadcast.in
broadcast.out(0).filter(_.country == "US") ~> usSpecificFilter ~> merge.in(0)
broadcast.out(1).filter(_.country != "US") ~> internationalFilter ~> merge.in(1)
merge.out ~> s.in // <--- changed sink to s.in
ClosedShape
})