Hi,
By default cluster sharding will distribute actors across the nodes in a cluster.
But I want to distribute actors to only few nodes among all in the cluster.
Here I created two shard regions according to incoming ports and I ran this codebase, it created actor within the specific nodes in a cluster.
if(port.equals(“2553”)||port.equals(“2554”)){
ActorRef shardingRegion = setupClusterSharding(actorSystem,“region1”);
actorSystem.actorOf(EntityCommandActor.props(shardingRegion), “entityCommand”);
actorSystem.actorOf(EntityQueryActor.props(shardingRegion), “entityQuery”);
}
else {
ActorRef shardingRegion = setupClusterSharding(actorSystem,“region2”);
actorSystem.actorOf(EntityCommandActor.props(shardingRegion), “entityCommand”);
actorSystem.actorOf(EntityQueryActor.props(shardingRegion), “entityQuery”);
}
private static ActorRef setupClusterSharding(ActorSystem actorSystem, String entityName) {
ClusterShardingSettings settings = ClusterShardingSettings.create(actorSystem);
return ClusterSharding.get(actorSystem).start(
entityName,
EntityActor.props(),
settings,
EntityMessage.messageExtractor()
);
}
Is it correct way of implementation ?
Please advice me.
Thanks