3
votes

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?

3

3 Answers

5
votes

The reason why your deployment is not picked up is that the routees are created as children of the router, hence they live at paths notificationServiceWorkers/*.

3
votes

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.

1
votes

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

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