Sharded Daemon Process

Warning

This module is currently marked as may change because it is a new feature that needs feedback from real usage before finalizing the API. This means that API or semantics can change without warning or deprecation period. It is also not recommended to use this module in production just yet.

Module info

To use Akka Sharded Daemon Process, you must add the following dependency in your project:

sbt
val AkkaVersion = "2.6.10"
libraryDependencies += "com.typesafe.akka" %% "akka-cluster-sharding-typed" % AkkaVersion
Maven
<properties>
  <akka.version>2.6.10</akka.version>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependency>
  <groupId>com.typesafe.akka</groupId>
  <artifactId>akka-cluster-sharding-typed_${scala.binary.version}</artifactId>
  <version>${akka.version}</version>
</dependency>
Gradle
versions += [
  AkkaVersion: "2.6.10",
  ScalaBinary: "2.13"
]
dependencies {
  compile group: 'com.typesafe.akka', name: "akka-cluster-sharding-typed_${versions.ScalaBinary}", version: versions.AkkaVersion
}
Project Info: Akka Cluster Sharding (typed)
Artifact
com.typesafe.akka
akka-cluster-sharding-typed
2.6.10
JDK versions
Adopt OpenJDK 8
Adopt OpenJDK 11
Scala versions2.12.11, 2.13.3
JPMS module nameakka.cluster.sharding.typed
License
Readiness level
Since 2.6.0, 2019-11-06
Home pagehttps://akka.io/
API documentation
Forums
Release notesakka.io blog
IssuesGithub issues
Sourceshttps://github.com/akka/akka

Introduction

Sharded Daemon Process provides a way to run N actors, each given a numeric id starting from 0 that are then kept alive and balanced across the cluster. When a rebalance is needed the actor is stopped and, triggered by a keep alive running on all nodes, started on a new node (the keep alive should be seen as an implementation detail and may change in future versions).

The intended use case is for splitting data processing workloads across a set number of workers that each get to work on a subset of the data that needs to be processed. This is commonly needed to create projections based on the event streams available from all the EventSourcedBehaviors in a CQRS application. Events are tagged with one out of N tags used to split the workload of consuming and updating a projection between N workers.

For cases where a single actor needs to be kept alive see Cluster Singleton

Basic example

To set up a set of actors running with Sharded Daemon process each node in the cluster needs to run the same initialization when starting up:

Scala
val tags = Vector("tag-1", "tag-2", "tag-3")
ShardedDaemonProcess(system).init("TagProcessors", tags.size, id => TagProcessor(tags(id)))
Java
List<String> tags = Arrays.asList("tag-1", "tag-2", "tag-3");
ShardedDaemonProcess.get(system)
    .init(
        TagProcessor.Command.class,
        "TagProcessors",
        tags.size(),
        id -> TagProcessor.create(tags.get(id)));

An additional factory method is provided for further configurability and providing a graceful stop message for the actor.

Addressing the actors

In use cases where you need to send messages to the daemon process actors it is recommended to use the system receptionist either with a single ServiceKey which all daemon process actors register themeselves to for broadcasts or individual keys if more fine grained messaging is needed.

Scalability

This cluster tool is intended for small numbers of consumers and will not scale well to a large set. In large clusters it is recommended to limit the nodes the sharded daemon process will run on using a role.

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.