Search code examples
scalaakkadispatcher

Create Akka Dispatcher programmatically


I have a scenario where I create actors on demand. I want to be able to define a Dispatcher and attach it to my actor programmatically.

The deal is: My ActorSystem is already running, which mean that it have already loaded all the Akka configurations.

Seems like the Dispatcher has to be defined in the application.conf before creating the ActorSystem, so I have two questions:

  1. Is there anyway to add new Akka configuration to an ActorSystem after it has been started?

  2. Is there another way to use Props[MyActor].withDispatcher("any-dispatcher") without the Dispatcher being defined in the ActorSystem configuration?


Solution

  • No, the dispatchers must be configured when the actor system is started, they can not be defined dynamically.

    If you have an app where you can restart the actor system the config library has options to programmatically define blocks, so you could generate a config based on the default one and then pass that config to the ActorSystem when you create it.