Quantcast
Viewing all articles
Browse latest Browse all 1366

Remembering entities with cluster sharding

I would like to use the remember entities feature to automatically recover my persistent actors every time my application starts up (after it was stopped or crashed or whatever other reason).

I am currently testing this locally but it does not work as expected. I am not sure if I am doing something wrong or if I miss-understand the feature in general.

What I am testing:

  • run my app with sbt run
  • send one of my persistent entities a message and let it store some event
  • stop the app by stopping sbt
  • start the app again with sbt run

I expected that the entity is recovered when I restart the app but this did not happen.
In the event journal table I see that there is an event stored for the entity and I am using the following code on app startup.

val sharding = ClusterSharding(system)
val shardingSettings = ClusterShardingSettings(system).withRememberEntities(true)

val TypeKey: EntityTypeKey[S#Command] = typeKeyForSaga(sagaTypeKeyName)
sharding.init(
  Entity(TypeKey)(ctx => saga.behaviour(ctx.entityId).asInstanceOf[Behavior[S#Command]])
    .withSettings(shardingSettings)
)

Am I missing something? or is this not supposed to work like this?

I am using akka-persistence-typed and akka-cluster-sharding 2.6.4 as part of the newest lagom framework version. So my app is a lagom service but in this case I did create the entities “myself” instead of using the PersistentEntity which comes with lagom.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1366

Trending Articles