我只是在播放akka流文档页面上提供的示例:http://doc.akka.io/docs/akka/2.4.2/scala/stream/stream-graphs.html
下面的例子没有产生输出。有人能指出这里有什么问题吗?
更新:它正在终端上工作。但在Intellij中失败
我的SBT依赖关系是:
val akkaVersion = "2.3.7"
val httpVersion = "2.0.4"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.11",
"com.typesafe.akka" %% "akka-stream-experimental" % httpVersion,
"com.typesafe.akka" %% "akka-http-core-experimental" % httpVersion,
"com.typesafe.akka" %% "akka-http-experimental" % httpVersion,
"com.typesafe.akka" %% "akka-http-spray-json-experimental" % httpVersion
)
计划:
import akka.stream.ClosedShape
object Test extends App {
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl._
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val ec = system.dispatcher
val source = Source(Stream.from(1))
val graph = RunnableGraph.fromGraph(GraphDSL.create() { implicit b =>
import GraphDSL.Implicits._
val zip = b.add(ZipWith((left: Int, right: Int) => left))
val bcast = b.add(Broadcast[Int](2))
val concat = b.add(Concat[Int]())
val start = Source.single(0)
source ~> zip.in0
zip.out.map { s => println(s); s } ~> bcast ~> Sink.ignore
zip.in1 <~ concat <~ start
concat <~ bcast
ClosedShape
})
graph.run()
Thread.sleep(1000000)
}