Akka Streams入口和奥特莱斯匹配

时间:2017-09-01 01:39:23

标签: scala akka-stream

以下是使用PartitionMerge的最简单图表,但是在运行时会出现以下错误: requirement failed: The inlets [] and outlets [] must correspond to the inlets [Merge.in0, Merge.in1] and outlets [Partition.out0, Partition.out1]

据我所知,该消息表明我输出的数量多于输入数或流量未连接数,但我似乎无法在这个简单的示例中看到不匹配的情况。

感谢任何帮助。

图表:

    def createGraph()(implicit actorSystem: ActorSystem): Graph[ClosedShape, Future[Done]] = {
      GraphDSL.create(Sink.ignore) { implicit builder: GraphDSL.Builder[Future[Done]] => s =>
          import GraphDSL.Implicits._
          val inputs: List[Int] = List(1, 2, 3, 4)
          val source: Source[Int, NotUsed] = Source(inputs)

          val messageSplit: UniformFanOutShape[Int, Int] = builder.add(Partition[Int](2, i => i%2))

          val messageMerge: UniformFanInShape[Int, Int] = builder.add(Merge[Int](2))

          val processEven: Flow[Int, Int, NotUsed] = Flow[Int].map(rc => {
            actorSystem.log.debug(s"even:  $rc")
            rc
          })

          val processOdd: Flow[Int, Int, NotUsed] = Flow[Int].map(rc => {
            actorSystem.log.debug(s"odd: $rc")
            rc
          })

          source ~> messageSplit.in
          messageSplit.out(0) -> processEven -> messageMerge.in(0)
          messageSplit.out(1) -> processOdd -> messageMerge.in(1)
          messageMerge.out ~> s
          ClosedShape
      }
    }

测试:

import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl.{Flow, GraphDSL, Merge, Partition, RunnableGraph, Sink, Source}
import akka.{Done, NotUsed}
import org.scalatest.FunSpec

import scala.concurrent.Future
class RoomITSpec extends FunSpec {

  implicit val actorSystem: ActorSystem = ActorSystem("RoomITSpec")
  implicit val actorCreator: ActorMaterializer = ActorMaterializer()
  describe("graph") {
    it("should run") {
      val graph = createGraph()
      RunnableGraph.fromGraph(graph).run
    }
  }
}

1 个答案:

答案 0 :(得分:1)

小句法错误。

var settings = {
    "async": true,
    "crossDomain": true,
    "url": "https://aaaaa.bbb.com/api/v1/users",
    "method": "POST",
    "headers": {
        "authorization": "Basic 5555555555555144455",//this for Api key + pw using basic authentication
        "cache-control": "no-cache",

    }
}

$.ajax(settings).done(function (response) {
    console.log(response);
});

而不是你写的:

// Notice the curly arrows
messageSplit.out(0) ~> processEven ~> messageMerge.in(0)
messageSplit.out(1) ~> processOdd ~> messageMerge.in(1)

您最终生成(并丢弃)元组而不是添加到图表中。