This example akka project should represent the concept of event sourcing.
It contains four Types of Actors
- RootActor: Holds the "AccountSupervisor" and "CommandBot" actors
- AccountSupervisor: Starts the "Account" actors and supervises them
- CommandBot: Sends a random amount of Commands to the Accounts
- Account: Holds a list of received events and a state which is derived from those
Command which gets converted to BalanceAdjusted after processing.
Tells the Account to adjust its balance based on the "adjust" argument.
final case class AdjustBalance(adjust: Int) extends Cmd
Command which gets converted to MoneyDeposited after processing.
Tells the Account to add "amount" to its balance.
final case class DepositMoney(amount: Int) extends Cmd
Account logs its current balance and is trying to replay all events to reproduce the current ActorState.
final case class GetBalance(returnTo: ActorRef[Cmd]) extends Cmd
Represents the current balance of the actor.
final case class ActorState(id: String, balance: Int) extends Cmd
Gets saved in the "Account" event Sequence after processing.
final case class BalanceAdjusted(adjusted: Int, sequenceNr: Int) extends Event
Gets saved in the "Account" event Sequence after processing.
final case class MoneyDeposited(amount: Int, sequenceNr: Int) extends Event
To run this application:
sbt run
To test this application:
sbt test
Blogbeitrag zum Sourcecode https://innfactory.de/softwareentwicklung/scala-akka-play-co/was-ist-event-sourcing-und-wie-funktioniert-es/