1
我有this应用程序使用Akka Streams和ReactiveMongo。没有用户定义的演员。该应用程序从main
方法启动。如何从主要方法中终止Akka actor系统?
问题是在main
方法完成后JVM将继续运行。这是我现在在做什么:
val g = (file: String) => RunnableGraph.fromGraph(GraphDSL.create(Sink.ignore) {
implicit builder =>
sink =>
import GraphDSL.Implicits._
// Source
val A: Outlet[(String, String)] = builder.add(Source.fromIterator(() => parseMovies(file).iterator)).out
// Flow
val B: FlowShape[(String, String), Either[String, Movie]] = builder.add(findMovie)
// Flow
val C: FlowShape[Either[String, Movie], Option[String]] = builder.add(persistMovie)
A ~> B ~> C ~> sink.in
ClosedShape
})
def main(args: Array[String]): Unit = {
require(args.size >= 1, "Path to file is required.")
g(args(0)).run
.onComplete(_ => Await.result(system.terminate(), 5.seconds))
}
我读过this线程,this,其中没有工作。 system.shutdown
已被弃用,我没有任何明确的演员要注意。我可以拨打电话system.exit
,但这并不优雅。
从日志中看来,Akka正试图关闭,但后来我看到一堆Mongo消息。
2017-01-13 11:35:57.320 [DEBUG] a.e.EventStream.$anonfun$applyOrElse$4 - shutting down: StandardOutLogger started
2017-01-13 11:36:05.397 [DEBUG] r.c.a.MongoDBSystem.debug - [Supervisor-1/Connection-2] ConnectAll Job running... Status: {{NodeSet None Node[localhost:27017: Primary (10/10 available connections), latency=6], auth=Set() }}
2017-01-13 11:36:05.420 [DEBUG] r.c.a.MongoDBSystem.debug - [Supervisor-1/Connection-2] RefreshAll Job running... Status: {{NodeSet None Node[localhost:27017: Primary (10/10 available connections), latency=6], auth=Set() }}
// more of MongoDBSystem.debug messages
为什么不会it.just.die?
你应该正确地关闭了'MongoDriver',因为它管理自己的底层演员系统,你不应该(也不能)访问 – cchantep
@cchantep你能更具体还是展示代码示例?关闭Mongo连接并没有帮助。 –
如果你仔细阅读我提到的'MongoDriver',而不是'MongoConnection' – cchantep