tree: f49f56b450d08c5f5191da5835a3bb50a1f0e5ed [path history] [tgz]
  1. project/
  2. src/
  3. .gitignore
  4. build.sbt
  5. COPYING
  6. LICENSE
  7. README.md
pekko-sample-persistence-scala/README.md

This example illustrates event sourcing with Apache Pekko Persistence.

Study the source code of the ShoppingCart.scala. A few things to note:

  • The actor is implemented with the EventSourcedBehavior
  • It defines Command, Event and State
  • Commands define replyTo: ActorRef to send a confirmation when the event has been successfully persisted
  • State is only updated in the event handler
  • withRetention to enable snapshotting
  • onPersistFailure defines restarts with backoff in case of failures

Tests are defined in ShoppingCartSpec.scala. To run the tests, enter:

sbt
sbt:pekko-sample-persistence-scala> test

The ShoppingCart application is expanded further in the pekko-sample-cqrs-scala sample. In that sample the events are tagged to be consumed by even processors to build other representations from the events, or publish the events to other services.