简体   繁体   中英

Akka Config - application.conf - Setting Dispatcher & Router

In Akka 2.2.0 I have a round robin routed Actor which I want to have a custom dispatcher sitting over.

In my application.conf I have;

durable-dispatcher {
  mailbox-type = akka.actor.mailbox.filebased.FileBasedMailboxType
}

akka.actor.deployment {
  /notificationServiceWorkers {
    dispatcher = durable-dispatcher
    router = round-robin
    nr-of-instances = 5
  }
}

Now when I try to create this actor like so;

ActorRef notificationServiceWorkers = akka.actorOf(Props.create(NotificationServiceActor.class)
   .withRouter(new FromConfig()), "notificationServiceWorkers")

The dispatcher is not picked up from the config and it uses the default dispatcher.

If I remove the .withRouter , Akka picks up the config for the dispatcher just fine but obviously its no longer routed.

If I add the .withDispatcher like so;

ActorRef notificationServiceWorkers = akka.actorOf(Props.create(NotificationServiceActor.class)
       .withDispatcher("durable-dispatcher")
       .withRouter(new FromConfig()), "notificationServiceWorkers")

It all works. The question is (its not clear from the doco) if I want to load a dispatcher and router configuration from the application.conf then why do I need to supply both in the Props creation? Is this a bug?

部署未被提取的原因是路由被创建为路由器的子节点,因此它们位于路径notificationServiceWorkers/*

In taking an in depth look at the Akka code inside LocalActorRefProvider , you can see inside of the actorOf that they only take the dispatcher from the deployment config if it's a non-routed actor. I imagine they have their reasons for this, but what it means for you is that if you are going to use a router and you want a different dispatcher (other than the default dispatcher), you will need to use the withDispatcher explicitly on the Props instance and you will not be able to get it from the config. Again, I don't know if this is a bug, but from the looks of their code, it appears they intentionally do not pull from the config when it's a routed actor.

As an addition to Roland Kuhn's answer, this is working:

"/notificationServiceWorkers/*" {
  dispatcher = durable-dispatcher
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM