stackoverflower
stackoverflower

Reputation: 4053

Is Akka ShardRegion.StartEntity message propagapted to entity actor?

I'm using Akka 2.5.2 with Scala 2.12.2.

The sharding doc mentions that in order to have crashed/rebalanced shards recovering their entities, the ShardRegion.ExtractShardI must handle the ShardRegion.StartEntity message.

And if an entity itself needs to recover its internal state, it must implement PersistenceActor. For this to work, the entity must have a unique persistenceId.

The problem is, when an entity is restarted, how does it find out its persistenceId? Is this passed in by the ShardRegion actor?

Upvotes: 0

Views: 447

Answers (1)

Diego Martinoia
Diego Martinoia

Reputation: 4662

No: a sharded actor does not receive (afaik) the StartEntity message, that is consumed by the region of the local node.

The persistenceId is something you override from the PersistentActor trait, something you must define yourself in a stable (i.e. always the same across restarts) way.

Normally, you tie the persistenceId to be the same as the entityId, and the latter you can normally retrieve from the name of the actor with self().path().name()

One way to go around this is to make sure that all messages sent to a sharded actor contain the entityId either by being wrapped in an "envelope" class, or by exposing a entityId of sort (which is the same that the extractor uses).

Upvotes: 1

Related Questions