I found the same question Akka cluster-sharding: Can Entry actors have dynamic props, but still wonder if things have been improved during the past five years.
The question is: Is it possible to pass arguments to the actor constructor which is instantiated by Akka ClusterSharding automatically? For example, pass an actor ID to the constructor?
Asked
Active
Viewed 101 times
0

user6502167
- 731
- 9
- 18
-
The new typed sharding api allows to access the entity id when creating the sharded behavior. See https://doc.akka.io/docs/akka/current/typed/cluster-sharding.html. ` sharding.init(Entity(TypeKey)(createBehavior = entityContext => Counter(entityContext.entityId)))`. Is that what you are looking for? – jrudolph Jan 21 '20 at 06:50
-
Thanks! Seems this is exactly what I need; the only issue is, I'm still using classic actor. I'm not quite comfortable with the typed actor, waiting for more use cases. – user6502167 Jan 22 '20 at 07:40
-
The only trick I've seen for this is parsing the actor path, which is icky. – Levi Ramsey Jan 23 '20 at 19:52