我在addtional conf文件中写了我的disptacher的设置,然后将它加载到application.conf中,但是当我给出调度程序位于我的文件中的完整路径时,调度程序不工作我也确保调度程序exsits或不使用if statarements
val config = ConfigFactory.load()
// an actor needs an ActorSystem
val system = ActorSystem("TestActorSystem",config)
if(system.dispatchers.hasDispatcher("akka.actor.directUserWriteMongoActor-dispatcher"))
{println("directUserWriteMongoActor-dispatcher exists")}
else
{
println("dispatcher does not exists")
}
当我运行时,directUserWriteMongoActor-dispatcher存在于控制台上,但是当我尝试通过代码附加它时
val DirectUserWriteMongoActor = system.actorOf(Props[DirectUserWriteMongoActor].withDispatcher("akka.actor.directUserWriteMongoActor-dispatcher"), name = "directwritemongoactorr")
DirectUserWriteMongoActor ! DirectUserWriteToMongo(directUser)
日志表明它使用的是default-dispatcher而不是我自己的名为directUserWriteMongoActor-dispatcher的调度程序 这是我的完整代码
application.conf
include "DirectUserWriteMongoActor"
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
}
DirectUserWriteMongoActor.conf
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
actor{
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
############################### Setting for a Dispatcher #####################################
directUserWriteMongoActor-dispatcher {
type = Dispatcher
executor = "fork-join-executor"
fork-join-executor {
parallelism-min = 2
parallelism-factor = 2.0
parallelism-max = 10
}
throughput = 10
} #end default-dispatcher
} #end Actor
} #end Akka
这是我的代码
object TestActor extends App{
val config = ConfigFactory.load()
val system = ActorSystem("TestActorSystem",config)
if(system.dispatchers.hasDispatcher("akka.actor.directUserWriteMongoActor-dispatcher"))
{println("directUserWriteMongoActor-dispatcher exists")}
else
{
println("directUserWriteMongoActor-dispatcher does not exists")
}
val DirectUserWriteMongoActor = system.actorOf(Props[DirectUserWriteMongoActor].withDispatcher("akka.actor.directUserWriteMongoActor-dispatcher"), name = "directwritemongoactorr")
DirectUserWriteMongoActor ! DirectUserWriteToMongo(directUser)
DirectUserWriteMongoActor.scala
case class DirectUserWriteToMongo (directuser:DirectUser)
class DirectUserWriteMongoActor extends Actor{
val log = Logging(context.system, this)
def receive = {
case DirectUserWriteToMongo(directuser) =>
log.debug("writing to mogo")
log.info("message received DirectUserWriteInMongo")
val directUserStore= new directUserStore
log.info("going to call store in mongo")
}}
这是打印在控制台上的输出
2015-04-27 10:40:01.392 INFO Slf4jLogger [TestActorSystem-akka.actor.default-dispatcher-2] -Slf4jLogger started
directUserWriteMongoActor-dispatcher exists
2015-04-27 10:40:02.262 INFO DirectUserWriteMongoActor [TestActorSystem-akka.actor.default-dispatcher-3] akka://TestActorSystem/user/directwritemongoactorr -message received DirectUserWriteInMongo
2015-04-27 10:40:02.263 INFO DirectUserWriteMongoActor [TestActorSystem-akka.actor.default-dispatcher-3] akka://TestActorSystem/user/directwritemongoactorr -going to call store in mongo
请帮助我在我的代码或我的conf设置中有什么问题disptacher在那里,但它不起作用为什么os那么 这应该打印
TestActorSystem-akka.actor.directUserWriteMongoActor-dispatcher-3
而不是
TestActorSystem-akka.actor.default-dispatcher-3
请帮助我,我第一次使用akka发送和其他配置文件
答案 0 :(得分:3)
您可能正在使用SimpleLogger。此记录器使用默认调度程序进行记录。
您的代码没有任何问题。包括:println(context.dispatcher)
到你的actor接收方法将通知你,他正在使用正确的directUserWriteMongoActor调度程序。
另一方面,如果将println(system.dispatcher)
添加到App对象,您会发现,在actor之外使用默认调度程序。这是正确的,因为您只指定了actor的调度程序,而不是全局使用的调度程序。