kostja
kostja

Reputation: 61568

Is there a way to use snapshots with PersistenceQuery

PersistentView has been deprecated in akka 2.4. The docs advise to switch to PersistenceQuery instead. However PersistenceQuery seems to be limited to the event journal only, without a capability to query the snapshot store.

Restoring a state from a large number of events takes some time, so the ability to use snapshots is important for me.

Is the deprecation a bit ahead of its time here? Should I continue to work with PersistentView or am I missing something? How do I work with snapshots using only PersistenceQuery?

Thank you

Upvotes: 6

Views: 324

Answers (1)

Bennie Krijger
Bennie Krijger

Reputation: 595

One way to do it:

  • Make the Actor you use as the "PersistentView" extend a PersistentActor.
  • Store your PersistentQuery offset in the state of the PersistentActor and save snapshots regularly.
  • Initially set query offset to the earliest offset.
  • In the receiveRecover set the query offset to the offset stored in the PersistentActor snapshot.

Example: https://github.com/benniekrijger/todo-service/blob/master/src/main/scala/com/todos/repository/TodoRepositoryView.scala

Upvotes: 1

Related Questions