Cluster singleton to use custom mailbox and dispatcher in typed actor system

In Java, the singleton actor in the system is initialized using the following construct:

ClusterSingleton singleton = ClusterSingleton.get(system);
ActorRef<Counter.Command> proxy =
    singleton.init(SingletonActor.of(Counter.create(), "GlobalCounter"));

Is there a way to pass a custom configuration to select custom mailbox and dispatcher ?

Typically the custom mailbox (and also dispatcher) is set in the config and the actor behavior is spawned using the config selector:

my-app {
  my-special-mailbox {
    mailbox-type = "akka.dispatch.SingleConsumerOnlyUnboundedMailbox"
    behavior, "DispatcherFromConfig", DispatcherSelector.fromConfig("your-dispatcher"));
1 Like

akka.cluster.typed.SingletonActor#withProps (so SingletonActor.of(...).withProps(...)) should make it possible to specify dispatcher and mailbox settings for a typed singleton.

How would we get Props in this case? to pass into withProps(...). I was not able to find an appropriate constructor to get Props or to convert from, Config for example

The DispatcherSelector.fromConfig method mentioned returns an which extends so you should be able to pass that to SingletonActor#withProps()

1 Like