使用反应式mongo驱动程序时,控制台scala应用程序不会停止 [英] Console scala app doesn't stop when using reactive mongo driver
问题描述
我正在通过 Reactive Mongo 驱动程序来使用Mongo数据库
I'm playing with Mongo database through the Reactive Mongo driver
import org.slf4j.LoggerFactory
import reactivemongo.api.MongoDriver
import reactivemongo.api.collections.default.BSONCollection
import reactivemongo.bson.BSONDocument
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
object Main {
val log = LoggerFactory.getLogger("Main")
def main(args: Array[String]): Unit = {
log.info("Start")
val conn = new MongoDriver().connection(List("localhost"))
val db = conn("test")
log.info("Done")
}
}
我的 build.sbt
文件:
lazy val root = (project in file(".")).
settings(
name := "simpleapp",
version := "1.0.0",
scalaVersion := "2.11.4",
libraryDependencies ++= Seq(
"org.reactivemongo" %% "reactivemongo" % "0.10.5.0.akka23",
"ch.qos.logback" % "logback-classic" % "1.1.2"
)
)
我运行时: sbt编译运行
我得到以下输出:
$ sbt compile run
[success] Total time: 0 s, completed Apr 25, 2015 5:36:51 PM
[info] Running Main
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
17:36:52.328 [run-main-0] INFO Main - Start
17:36:52.333 [run-main-0] INFO Main - Done
应用程序不会停止....:/
And application doesn't stop.... :/
我必须按 Ctrl + C 杀死它
我读过 MongoDriver()
创建 ActorSystem
,所以我尝试使用 conn.close()
手动关闭连接,但是我得到了
I've read that MongoDriver()
creates ActorSystem
so I tried to close connection manually with conn.close()
but I get this:
[info] Running Main
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
17:42:23.252 [run-main-0] INFO Main - Start
17:42:23.258 [run-main-0] INFO Main - Done
17:42:23.403 [reactivemongo-akka.actor.default-dispatcher-2] ERROR reactivemongo.core.actors.MongoDBSystem - (State: Closing) UNHANDLED MESSAGE: ChannelConnected(-973180998)
[INFO] [04/25/2015 17:42:23.413] [reactivemongo-akka.actor.default-dispatcher-3] [akka://reactivemongo/deadLetters] Message [reactivemongo.core.actors.Closed$] from Actor[akka://reactivemongo/user/$b#-1700211063] to Actor[akka://reactivemongo/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[INFO] [04/25/2015 17:42:23.414] [reactivemongo-akka.actor.default-dispatcher-3] [akka://reactivemongo/user/$a] Message [reactivemongo.core.actors.Close$] from Actor[akka://reactivemongo/user/$b#-1700211063] to Actor[akka://reactivemongo/user/$a#-1418324178] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
应用也不会退出
那么,我在做什么错?我找不到答案...
So, what am i doing wrong? I can'f find answer...
在我看来,官方文档并没有解释我是否应该关心正常关机。
And it seems to me that official docs doesn't explain whether i should care about graceful shutdown at all.
我在控制台应用程序方面经验不足,我在项目中使用play框架,但我想创建可与mongodb一起使用的子项目
I don't have much experience with console apps, i use play framework in my projects but i want to create sub-project that works with mongodb
我看到了许多模板(在激活器中),例如: Play + Reactive Mongo , Play + Akka + Mongo ,但是没有 Scala + Reactive Mongo ,它将说明如何正常工作:/
I see many templates (in activator) such as: Play + Reactive Mongo, Play + Akka + Mongo but there's no Scala + Reactive Mongo that would explain how to work properly :/
推荐答案
这似乎是Reactive Mongo的已知问题,< a href = https://github.com/ReactiveMongo/ReactiveMongo/issues/213 rel = nofollow>查看GitHub上的相关线程
This looks like a known issue with Reactive Mongo, see the relevant thread on GitHub
reid-spencer的拉动请求#241中引入了针对此问题的修复程序> ,于2015年2月3日合并
A fix for this was introduced in this pull request #241 by reid-spencer, merged on the 3rd of February 2015
您应该能够使用较新的版本。如果自2月以来未发布任何版本,则可以尝试签出包含此修复程序的版本并自己构建代码。
You should be able to fix it by using a newer version. If no release has been made since February, you could try checking out a version that includes this fix and building the code yourself.
据我所知,没有在版本0.10.5的发行说明中提到了此错误修正
As far as I can see, there's no mention of this bugfix in the release notes for version 0.10.5
- 错误修正:
- BSON库:修复BSONDateTimeNumberLike类型类
- 游标:修复异常传播
- 命令:修复某些情况下的确定反序列化
- 命令:修复CollStatsResult
- 命令:修复聚合中的AddToSet
- 核心:修复某些情况下的连接泄漏
- GenericCollection:不要忽略save()中的WriteConcern
- GenericCollection:不要忽略大容量插入中的WriteConcern
- GridFS:修复uploadDate反序列化字段
- Inde xes:修复了升序和降序的解析
- 宏:修复了类型别名
- 宏:允许自定义注释
- Bugfixes:
- BSON library: fix BSONDateTimeNumberLike typeclass
- Cursor: fix exception propagation
- Commands: fix ok deserialization for some cases
- Commands: fix CollStatsResult
- Commands: fix AddToSet in aggregation
- Core: fix connection leak in some cases
- GenericCollection: do not ignore WriteConcern in save()
- GenericCollection: do not ignore WriteConcern in bulk inserts
- GridFS: fix uploadDate deserialization field
- Indexes: fix parsing for Ascending and Descending
- Macros: fix type aliases
- Macros: allow custom annotations
提交者的名字也不会出现:
The name of the committer does not appear as well:
以下是此版本中包含的提交的列表(从0.9开始,最高的提交是最新的):
Here is the list of the commits included in this release (since 0.9, the top commit is the most recent one):
$ git shortlog -s -n refs/tags/v0.10.0..0.10.5.x.akka23
39 Stephane Godbillon
5 Andrey Neverov
4 lucasrpb
3 Faissal Boutaounte
2 杨博 (Yang Bo)
2 Nikolay Sokolov
1 David Liman
1 Maksim Gurtovenko
1 Age Mooij
1 Paulo "JCranky" Siqueira
1 Daniel Armak
1 Viktor Taranenko
1 Vincent Debergue
1 Andrea Lattuada
1 pavel.glushchenko
1 Jacek Laskowski
查看 0.10.5.0.akka23
的提交历史记录(您在 build.sbt
),似乎此修复程序未合并到其中。
Looking at the commit history for 0.10.5.0.akka23
(the one you reference in build.sbt
), it seems the fix was not merged into it.
这篇关于使用反应式mongo驱动程序时,控制台scala应用程序不会停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!