Scala Akka Streams项目无法编译,“value~>不是akka.streams.Outlet [In]的成员”

时间:2017-11-18 16:24:35

标签: scala intellij-idea sbt akka akka-stream

我在Scala项目中使用Akka Streams API,使用SBT插件在Intellij IDEA中工作。我有一个工作池流程,如下所述:https://doc.akka.io/docs/akka/current/scala/stream/stream-cookbook.html。这是我的代码:

"aggregations": {
    "employees_per_month": {
        "buckets": [
            {
                "key_as_string": "2017-01-01",
                "doc_count": 1
            },
            {
                "key_as_string": "2017-02-01",
                "doc_count": 2
            },
            {
                "key_as_string": "2017-03-01",
                "doc_count": 2
            },
            {
                "key_as_string": "2017-04-01",
                "doc_count": 3
            },
            {
                "key_as_string": "2017-05-01",
                "doc_count": 3
            },
            {
                "key_as_string": "2017-06-01",
                "doc_count": 2
            }
        ]
    }
}

由于某种原因,项目现在无法编译,出现此错误:package streams import akka.NotUsed import akka.stream.scaladsl.{Balance, Flow, GraphDSL, Merge} import akka.stream.{FlowShape, Graph} object WorkerPoolFlow { def apply[In, Out]( worker: Flow[In, Out, Any], workerCount: Int): Graph[FlowShape[In, Out], NotUsed] = { GraphDSL.create() { implicit b => val balance = b.add(Balance[In](workerCount, waitForAllDownstreams = true)) val merge = b.add(Merge[Out](workerCount)) for (i <- 0 until workerCount) balance.out(i) ~> worker.async ~> merge.in(i) FlowShape( balance.in, merge.out) } } }

直到今天才编好。我所知道的唯一变化是安装Scala linter插件value ~> is not a member of akka.stream.Outlet[In],并在scalafmt中导入一些新库。这是我的build.sbt

build.sbt

我尝试重新加载SBT,从IDEA之外的SBT构建,删除并重新添加依赖项,以及清理项目,没有运气。

1 个答案:

答案 0 :(得分:2)

导入GraphDSL.Implicits._

object WorkerPoolFlow {
  def apply[In, Out](
    worker: Flow[In, Out, Any],
    workerCount: Int):
  Graph[FlowShape[In, Out], NotUsed] = {
    import GraphDSL.Implicits._

    GraphDSL.create() { implicit b =>
      ...
    }
  }
}