Classic Multi-DC Cluster

This chapter describes how Akka Cluster can be used across multiple data centers, availability zones or regions.

For the full documentation of this feature and for new projects see Multi-DC Cluster.

Membership

You can retrieve information about what data center a member belongs to:

Scala
sourceval cluster = Cluster(system)
// this node's data center
val dc = cluster.selfDataCenter
// all known data centers
val allDc = cluster.state.allDataCenters
// a specific member's data center
val aMember = cluster.state.members.head
val aDc = aMember.dataCenter
Java
sourcefinal Cluster cluster = Cluster.get(system);
// this node's data center
String dc = cluster.selfDataCenter();
// all known data centers
Set<String> allDc = cluster.state().getAllDataCenters();
// a specific member's data center
Member aMember = cluster.state().getMembers().iterator().next();
String aDc = aMember.dataCenter();

For the full documentation of this feature and for new projects see Multi-DC Cluster.

Cluster Singleton

This is how to create a singleton proxy for a specific data center:

Scala
sourceval proxyDcB = system.actorOf(
  ClusterSingletonProxy.props(
    singletonManagerPath = "/user/consumer",
    settings = ClusterSingletonProxySettings(system).withDataCenter("B")),
  name = "consumerProxyDcB")
Java
sourceActorRef proxyDcB =
    system.actorOf(
        ClusterSingletonProxy.props(
            "/user/consumer",
            ClusterSingletonProxySettings.create(system)
                .withRole("worker")
                .withDataCenter("B")),
        "consumerProxyDcB");

If using the own data center as the withDataCenter parameter that would be a proxy for the singleton in the own data center, which is also the default if withDataCenter is not given.

For the full documentation of this feature and for new projects see Multi-DC Cluster.

Cluster Sharding

This is how to create a sharding proxy for a specific data center:

Scala
sourceval counterProxyDcB: ActorRef = ClusterSharding(system).startProxy(
  typeName = "Counter",
  role = None,
  dataCenter = Some("B"),
  extractEntityId = extractEntityId,
  extractShardId = extractShardId)
Java
sourceActorRef counterProxyDcB =
    ClusterSharding.get(system)
        .startProxy(
            "Counter",
            Optional.empty(),
            Optional.of("B"), // data center name
            messageExtractor);

For the full documentation of this feature and for new projects see Multi-DC Cluster.

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.