我有一个非常简单的数据库编写器参与者,只是用于使用 Casbah 向 Mongo 写入一些条目,但它拒绝(没有错误)在连接到 DB 后接收任何消息。如果我从演员中删除client
和db
vals,它会收到消息。我也尝试过封装与某个对象的连接,但在连接到数据库后它仍然无法正常工作。
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(....)
....
}
....
}
如何修复?