Spekka Stateful Akka Persistence

javadoc maven

This library provides StatefulFlowBackend.EventBased and StatefulFlowBackend.DurableState implementations based on Akka Persistence.

To use this library add the following dependencies:

sbt
val AkkaVersion = "2.6.16"
libraryDependencies ++= Seq(
  "io.github.spekka" %% "spekka-stateful" % "0.1.0",
  "com.typesafe.akka" %% "akka-stream" % AkkaVersion,
  "com.typesafe.akka" %% "akka-stream-typed" % AkkaVersion,
  "com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion,
  "com.typesafe.akka" %% "akka-persistence-typed" % AkkaVersion
)
Maven
<properties>
  <akka.version>2.6.16</akka.version>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependencies>
  <dependency>
    <groupId>io.github.spekka</groupId>
    <artifactId>spekka-stateful_${scala.binary.version}</artifactId>
    <version>0.1.0</version>
  </dependency>
  <dependency>
    <groupId>com.typesafe.akka</groupId>
    <artifactId>akka-stream_${scala.binary.version}</artifactId>
    <version>${akka.version}</version>
  </dependency>
  <dependency>
    <groupId>com.typesafe.akka</groupId>
    <artifactId>akka-stream-typed_${scala.binary.version}</artifactId>
    <version>${akka.version}</version>
  </dependency>
  <dependency>
    <groupId>com.typesafe.akka</groupId>
    <artifactId>akka-actor-typed_${scala.binary.version}</artifactId>
    <version>${akka.version}</version>
  </dependency>
  <dependency>
    <groupId>com.typesafe.akka</groupId>
    <artifactId>akka-persistence-typed_${scala.binary.version}</artifactId>
    <version>${akka.version}</version>
  </dependency>
</dependencies>
Gradle
def versions = [
  AkkaVersion: "2.6.16",
  ScalaBinary: "2.13"
]
dependencies {
  implementation "io.github.spekka:spekka-stateful_${versions.ScalaBinary}:0.1.0"
  implementation "com.typesafe.akka:akka-stream_${versions.ScalaBinary}:${versions.AkkaVersion}"
  implementation "com.typesafe.akka:akka-stream-typed_${versions.ScalaBinary}:${versions.AkkaVersion}"
  implementation "com.typesafe.akka:akka-actor-typed_${versions.ScalaBinary}:${versions.AkkaVersion}"
  implementation "com.typesafe.akka:akka-persistence-typed_${versions.ScalaBinary}:${versions.AkkaVersion}"
}

Event Based

In order to create an event based Akka Persistence backend you can use: AkkaPersistenceStatefulFlowBackend.EventBased[State, Ev].

You can specify:

  • The persistence plugin (see Akka Persistence)
  • The retention criteria, disabled by default (see Akka Persistence)
  • The number of partitions to tag the events, 1 by default (see Akka Projection)
  • The parallelism used to run side effects, 1 by default

You can further modify the backends by using the following methods:

  • withEventAdapter: Specify an event adapter (see Akka Persistence)
  • withSnapshotAdapter: Specify a snapshot adapter (see AKka Persistence)
  • withEventCodec: Specify an implicit Codec[Ev] instance making event serialization handled transparently by Spekka
  • withSnapshotCodec: Specify an implicit Codec[State] instance making state serialization handled transparently by Spekka

Durable State

In order to create a durable state Akka Persistence backend you can use: AkkaPersistenceStatefulFlowBackend.DurableState[State].

You can specify:

  • The persistence plugin (see Akka Persistence)
  • The parallelism used to run side effects, 1 by default

You can further modify the backends by using the following methods:

  • withSnapshotAdapter: Specify a snapshot adapter (see AKka Persistence)
  • withSnapshotCodec: Specify an implicit Codec[State] instance making state serialization handled transparently by Spekka