Spekka Stateful Sharding

javadoc maven

This library extends Spekka’s stateful flows by distributing them on a cluster via Akka Cluster Sharding.

To use this library add the following dependencies:

sbt
val AkkaVersion = "2.6.16"
libraryDependencies ++= Seq(
  "io.github.spekka" %% "spekka-stateful" % "0.1.1",
  "com.typesafe.akka" %% "akka-stream" % AkkaVersion,
  "com.typesafe.akka" %% "akka-stream-typed" % AkkaVersion,
  "com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion,
  "com.typesafe.akka" %% "akka-cluster-sharding-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.1</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-cluster-sharding-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.1"
  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-cluster-sharding-typed_${versions.ScalaBinary}:${versions.AkkaVersion}"
}

Usage

In order to use the sharding support you need to create a ShardedStatefulFlowRegistry:

sourceval registry = StatefulFlowRegistry(30.seconds)(typedSystem)
val shardedRegistry =
  ShardedStatefulFlowRegistry(registry, ClusterSharding(typedSystem), 30.seconds)(typedSystem)

and use the obtained sharded registry to register those flows you want to be sharded on the cluster.

The StatefulFlowBuilder obtained as a result of the registration can be used as if it were registered on the base registry.