Snapshot store plugin
The snapshot plugin enables storing and loading snapshots for event sourced persistent actors.
Schema
The snapshot table need to be created in the configured database, see schema definition in Creating the schema.
Configuration
To enable the snapshot plugin to be used by default, add the following line to your Pekko application.conf:
pekko.persistence.snapshot-store.plugin = "pekko.persistence.r2dbc.snapshot"
It can also be enabled with the snapshotPluginId for a specific EventSourcedBehavior and multiple plugin configurations are supported.
See also Configuration.
Reference configuration
The following can be overridden in your application.conf for the snapshot specific settings:
sourcepekko.persistence.r2dbc {
snapshot {
class = "org.apache.pekko.persistence.r2dbc.snapshot.R2dbcSnapshotStore"
table = "snapshot"
# Otherwise it would be a pinned dispatcher, see https://github.com/akka/akka/issues/31058
plugin-dispatcher = "pekko.actor.default-dispatcher"
dialect = ${pekko.persistence.r2dbc.dialect}
schema = ${pekko.persistence.r2dbc.schema}
use-connection-factory = ${pekko.persistence.r2dbc.use-connection-factory}
log-db-calls-exceeding = ${pekko.persistence.r2dbc.log-db-calls-exceeding}
}
}
Usage
The snapshot plugin is used whenever a snapshot write is triggered through the Pekko Persistence APIs.
Retention
The R2DBC snapshot plugin only ever keeps one snapshot per persistence id in the database. If a keepNSnapshots > 1 is specified for an EventSourcedBehavior that setting will be ignored.
The reason for this is that there is no real benefit to keep multiple snapshots around on a relational database with a high consistency.