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 Akka application.conf:

akka.persistence.snapshot-store.plugin = "akka.persistence.r2dbc.snapshot"

It can also be enabled with the snapshotPluginId for a specific EventSourcedBehavior and multiple plugin configurations are supported.

See also Connection configuration.

Reference configuration

The following can be overridden in your application.conf for the snapshot specific settings:

sourceakka.persistence.r2dbc {
  snapshot {
    class = "akka.persistence.r2dbc.snapshot.R2dbcSnapshotStore"
    table = "snapshot"

    # Otherwise it would be a pinned dispatcher, see https://github.com/akka/akka/issues/31058
    plugin-dispatcher = "akka.actor.default-dispatcher"
  }
}

Usage

The snapshot plugin is used whenever a snapshot write is triggered through the Akka 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.

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.