Classic Multi-DC Cluster
This chapter describes how Pekko 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
-
source
val 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
-
source
final 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
-
source
val proxyDcB = system.actorOf( ClusterSingletonProxy.props( singletonManagerPath = "/user/consumer", settings = ClusterSingletonProxySettings(system).withDataCenter("B")), name = "consumerProxyDcB")
- Java
-
source
ActorRef 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
-
source
val counterProxyDcB: ActorRef = ClusterSharding(system).startProxy( typeName = "Counter", role = None, dataCenter = Some("B"), extractEntityId = extractEntityId, extractShardId = extractShardId)
- Java
-
source
ActorRef 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.