Я не нашел способа (документация и API) для удаления старых снимков с помощью Akka Persistence Typed.С простым API я использовал:
override def receiveCommand: Receive = {
case SaveSnapshotSuccess(metadata) =>
deleteSnapshots(SnapshotSelectionCriteria.create(metadata.sequenceNr, metadata.timestamp - 1))
case c: C => {
val snd = sender()
c.validate(persistenceId, state).fold(
error => snd ! Left(error),
event => {
persist(event) { _ =>
state = eventHandler.handle(event)(state)
saveSnapshot(state)
snd ! Right(event)
}
}
)
}
}
Но с новым API я не могу найти способ.
def behavior(persistenceId: String): Behavior[BoardCommand] = PersistentBehaviors
.receive[BoardCommand, BoardEvent, Option[states.Board]](
persistenceId, None,
(state, cmd)=> {
cmd.validate(persistenceId, state ).fold(
error => {
cmd.replyTo ! Left(error)
Effect.none[BoardEvent, Option[states.Board]]
},
v => {
cmd.replyTo ! Right(v)
Effect.persist(v)
})
},
(state, event)=> BoardEventHandler.handle(event)(state)
).snapshotEvery(1)