【问题标题】:Scala Akka Streams project fails to compile, "value ~> is not a member of akka.streams.Outlet[In]"Scala Akka Streams 项目编译失败,“value ~> is not a member of akka.streams.Outlet[In]”
【发布时间】:2018-05-02 06:31:27
【问题描述】:

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

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)
    }
  }
}

由于某种原因,项目现在无法编译,出现以下错误:value ~&gt; is not a member of akka.stream.Outlet[In]

直到今天它编译得很好。我知道的唯一改变是安装一个 Scala linter 插件scalafmt,并在build.sbt 中导入一些新库。这是我的build.sbt

name := "myProject"

version := "0.1"

scalaVersion := "2.11.11"

unmanagedJars in Compile += file("localDep1.jar")
unmanagedJars in Compile += file("localDep2.jar")

libraryDependencies += "io.spray" %%  "spray-json" % "1.3.3"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.6"
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.5.6"
libraryDependencies += "com.typesafe.akka" %% "akka-testkit" % "2.5.6" % Test
libraryDependencies += "com.typesafe.akka" %% "akka-stream-testkit" % "2.5.6" % Test
libraryDependencies += "com.47deg" %% "fetch" % "0.6.0"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"

我尝试过重新加载 SBT、在 IDEA 之外从 SBT 构建、删除和重新添加依赖项以及清理项目,但没有成功。

【问题讨论】:

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


    【解决方案1】:

    导入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 =>
          ...
        }
      }
    }
    

    【讨论】:

    • 好吧。我想我一直盯着屏幕太久了。感谢您的完整性检查!
    猜你喜欢
    • 2015-01-27
    • 2019-08-19
    • 2014-07-17
    • 2015-08-27
    • 2014-10-22
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    相关资源
    最近更新 更多