Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 使用一个分区来决定一个流是否应该转到下一个流,如果不应该,让流从一开始就拾取下一个滴答声(Akka)_Scala_Akka_Akka Stream - Fatal编程技术网

Scala 使用一个分区来决定一个流是否应该转到下一个流,如果不应该,让流从一开始就拾取下一个滴答声(Akka)

Scala 使用一个分区来决定一个流是否应该转到下一个流,如果不应该,让流从一开始就拾取下一个滴答声(Akka),scala,akka,akka-stream,Scala,Akka,Akka Stream,我想创建一个包含4个主要步骤(FlowShapes)的流,在第一个和第二个步骤之后,我想创建一个分区,该分区将决定是否有理由转到下一个步骤,如果没有下沉,那么流将稍后拾取它并从头开始,但我不确定这是一种方式,因为我只使用了sink.ignore,看起来是这样的: def mainFlow: Flow[MyGraphElement, MyGraphElement, NotUsed] = Flow.fromGraph(GraphDSL.create() { implicit builder =&

我想创建一个包含4个主要步骤(FlowShapes)的流,在第一个和第二个步骤之后,我想创建一个分区,该分区将决定是否有理由转到下一个步骤,如果没有下沉,那么流将稍后拾取它并从头开始,但我不确定这是一种方式,因为我只使用了sink.ignore,看起来是这样的:

  def mainFlow: Flow[MyGraphElement, MyGraphElement, NotUsed] = Flow.fromGraph(GraphDSL.create() { implicit builder =>

    // FlowShape's
    // those flow shapes preforming api calls + updating the db with result
    val firstShape = builder.add(firstFlowShape)
    val secondShape = builder.add(secondFlowShape)
    val thirdShape = builder.add(thirdFlowShape)
    //  this flow shape will set the task to beginning mode so it will be picked up again by the stream
    val clearTaskShape = builder.add(clearTaskFlowShape)
    //  this flow shape will decide if this element needs to move to final status so it wont be pickd up by this stream anymore, otherwise it will also clear the task so it will be picked up again by the stream
    val evaluatorShape = builder.add(evaluatorFlowShape)

    //  UniformFanOutShape's
    // based on certain fields I want to decide here if there is need to go to the next step, if no need I want to sink the element and have the stream pick it up next time
    val shouldGoToSecondShape = builder.add(shouldGoToSecondShapePart)
    val shouldGoToThirdSahpe = builder.add(shouldGoToThirdShapePart)

    firstShape ~> shouldGoToSecondShape
          shouldGoToSecondShape.out(1) ~> clearTaskShape ~> Sink.ignore
          shouldGoToSecondShape.out(0) ~> secondShape ~> shouldGoToThirdSahpe
                shouldGoToThirdSahpe.out(1) ~> clearTaskShape ~> Sink.ignore
                shouldGoToThirdSahpe.out(0) ~> thirdShape ~> evaluatorShape


    FlowShape(firstShape.in, evaluatorShape.out)
  })

  def shouldGoToSecondShapePart: Partition[MyGraphElement] = {
    val portMapper = (elem: MyGraphElement) =>
      if (elem.myElement.someField == ProcessingStatus.Done ) 0 else 1
    Partition[MyGraphElement](2, portMapper)
  }

  def shouldGoToThirdShapePart Partition[MyGraphElement] = {
    val portMapper = (elem: MyGraphElement) =>
      if (elem.myElement.someOtherField == ProcessingStatus.Done ) 0 else 1
    Partition[MyGraphElement](2, portMapper)
  }

这样做的正确方法是什么?

您能完成您的示例吗?@TomerShetah您建议删除一些代码吗?因为我所需要的主要是形状之间的连接,我想知道这样发送东西到水槽中,以便在下一个滴答声中拾取它们是否是正确的方法。不确定您希望我完成什么,我添加了一些注释,这些注释应该可以很好地解释其中的部分,这样我就不需要用太多的代码来混淆您,例如
clearTaskShape
应该是一个接收器,而不是流?@TomerShetah问题是clearTaskFlowShape应该转到db并再次标记任务a就绪,以便在下一个滴答声拾取它,所以我认为它是从哪里拾取的流是有意义的?我从
clearTaskShape
中看到,您总是发送到
Sink.ignore
,所以我想应该是
Sink
本身。你可以做你正在做的事。这是有效的。但问题是,这对你来说是最好的?你能完成你的例子吗?@TomerShetah你建议拿出一些代码吗?因为我所需要的主要是形状之间的连接,我想知道这样发送东西到水槽中,以便在下一个滴答声中拾取它们是否是正确的方法。不确定您希望我完成什么,我添加了一些注释,这些注释应该可以很好地解释其中的部分,这样我就不需要用太多的代码来混淆您,例如
clearTaskShape
应该是一个接收器,而不是流?@TomerShetah问题是clearTaskFlowShape应该转到db并再次标记任务a就绪,以便在下一个滴答声拾取它,所以我认为它是从哪里拾取的流是有意义的?我从
clearTaskShape
中看到,您总是发送到
Sink.ignore
,所以我想应该是
Sink
本身。你可以做你正在做的事。这是有效的。但问题是这对你来说是最好的吗?