演员(Akka)在DB连接后没有收到消息

时间:2013-02-07 09:52:44

标签: mongodb scala akka

我有一个非常简单的数据库编写器actor,只是为了用Casbah向Mongo编写一些条目,但它在连接到DB之后拒绝接收任何消息(没有错误)。如果我从actor中删除clientdb个val,它会收到消息。我还尝试将连接封装到某个对象,但在连接到DB之后仍然无效。

class DBWriter extends Actor with ActorLogging {
  val client = MongoClient(host, port)
  val db     = client(dbName)

  def receive = {
    case Write(collection, entry) => db(collection).save(entry)
  }
}

class StatisticsActor extends Actor with ActorLogging {
  val writer = context.actorOf(Props[DBWriter], "dbWriterActor")
  def receive = {
    case mes: SM => writer ! Write(....)
    case NoConnection => writer ! Write(....)
    case NCTime(time) => writer ! Write(....)
    ....
  }
  ....
}

如何解决?

1 个答案:

答案 0 :(得分:0)

发现问题。这很简单,问题在于线程,演员只是没有足够的时间连接到mongo并写入它,所有测试都传递到那一刻。