Custom dispatcher for specific sharded actor

46 Views Asked by At

Is there any way to assign custom dispatcher for specific sharded actor? I have found example for non sharded actor but not with sharded actor.

1

There are 1 best solutions below

0
Levi Ramsey On

For Typed Cluster Sharding, you would define the dispatcher as part of Props and when initializing sharding, you would tell sharding to make the actors incarnating a given type of Entity use the specified dispatcher.

In Scala, this could look like:

val entityProps = Props.empty.withDispatcherFromConfig("config-path-to-dispatcher-definition")
val createBehaviorFn: (EntityContext[MyEntity.Command]) => Behavior[MyEntity.Command] = ???
val typeKey = EntityTypeKey[MyEntity.Command]("my-entity")
val myEntity = Entity(typeKey)(createBehaviorFn).withEntityProps(entityProps)

sharding.init(myEntity)

In Classic Cluster Sharding, the broad idea is similar (except you use Classic Props instead of Typed Props), but it's been too long since I've really used Classic.