diff --git a/build.sbt b/build.sbt index 6b3dd80..80a4c78 100644 --- a/build.sbt +++ b/build.sbt @@ -5,6 +5,6 @@ version := "0.1" scalaVersion := "2.12.4" libraryDependencies ++= Seq( - "com.typesafe.akka" %% "akka-persistence-typed" % "2.5-SNAPSHOT", + "com.typesafe.akka" %% "akka-persistence-typed" % "2.5.23", "org.fusesource.leveldbjni" % "leveldbjni-all" % "1.8" -) \ No newline at end of file +) diff --git a/src/main/scala/com/ojha/persistence/typedExample.scala b/src/main/scala/com/ojha/persistence/typedExample.scala index 25fbba3..bdd7e43 100644 --- a/src/main/scala/com/ojha/persistence/typedExample.scala +++ b/src/main/scala/com/ojha/persistence/typedExample.scala @@ -1,8 +1,8 @@ package com.ojha.persistence import akka.actor.typed.Behavior -import akka.persistence.typed.scaladsl.PersistentActor -import akka.persistence.typed.scaladsl.PersistentActor.Effect +import akka.persistence.typed.PersistenceId +import akka.persistence.typed.scaladsl.{Effect, EventSourcedBehavior} sealed trait TypedExampleCommand extends Serializable case class TypedExampleWriteCommand(data: String) extends TypedExampleCommand @@ -27,22 +27,18 @@ object TypedExampleMain extends App { } object TypedExample { - - def behavior: Behavior[TypedExampleCommand] = - PersistentActor.immutable[TypedExampleCommand, TypedEvent, TypedExampleState]( - persistenceId = "example-id", - initialState = new TypedExampleState, - commandHandler = PersistentActor.CommandHandler { - (_, state, cmd) ⇒ - cmd match { - case TypedExampleWriteCommand(data) => Effect.persist(TypedEvent(s"$data ${state.size}")) - case TypedExamplePrint => println(state); Effect.none - } - }, + def behavior: Behavior[TypedExampleCommand] = { + EventSourcedBehavior[TypedExampleCommand, TypedEvent, TypedExampleState]( + persistenceId = PersistenceId("example-id"), + emptyState = new TypedExampleState, + commandHandler = + (state, cmd) => cmd match { + case TypedExampleWriteCommand(data) => Effect.persist(TypedEvent(s"$data ${state.size}")) + case TypedExamplePrint => println(state); Effect.none + }, eventHandler = (state, event) ⇒ event match { case TypedEvent(_) => state.updated(event) - } + }, ) - + } } -