Akka dispatcher not working

I write my dispatcher setting in an additional conf file and then load it in application.conf, but the dispatcher doesn't work when I give the full path where the dispatcher located in my file is also sure its exsits or not using 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")
      }

      

when i run that directUserWriteMongoActor-dispatcher exists in the console, but when i try to connect it via code

 val DirectUserWriteMongoActor = system.actorOf(Props[DirectUserWriteMongoActor].withDispatcher("akka.actor.directUserWriteMongoActor-dispatcher"), name = "directwritemongoactorr")
      DirectUserWriteMongoActor ! DirectUserWriteToMongo(directUser)

      

log indicates that it is using the default dispatcher and not my own dispatcher named directUserWriteMongoActor-dispatcher here is my complete code

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        

      

and here is my code

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")
}}

      

here is the output printed to the console

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

      

please help me what is wrong in my code or in my config was there but it doesn't work why os is so It should be printed

TestActorSystem-akka.actor.directUserWriteMongoActor-dispatcher-3

      

instead of this

TestActorSystem-akka.actor.default-dispatcher-3

      

please help me also i am using akka manager and additional conf files for the first time

+3


source to share


1 answer


You are probably using SimpleLogger. This logger uses the default manager for logging.

There is nothing wrong with the code. Including: println(context.dispatcher)

your accept method of your actor will tell you that it is using the correct directUserWriteMongoActor dispatcher.



On the other hand, if you add println(system.dispatcher)

to your App object, you know that outside of the actor, the default dispatcher is used. This is correct since you only specified the actor's dispatcher, not the globally used dispatcher.

+3


source







All Articles