diff --git a/src/main/java/cluster/sharding/Runner.java b/src/main/java/cluster/sharding/Runner.java index 3dc1cab..723b8bb 100644 --- a/src/main/java/cluster/sharding/Runner.java +++ b/src/main/java/cluster/sharding/Runner.java @@ -27,11 +27,14 @@ private static void startupClusterNode() { actorSystem.actorOf(ClusterListenerActor.props(), "clusterListener"); ActorRef httpServer = actorSystem.actorOf(HttpServerActor.props(), "httpServer"); - ActorRef shardingRegion = setupClusterSharding(actorSystem, httpServer); - createClusterSingletonManagerActor(actorSystem, httpServer); - actorSystem.actorOf(EntityCommandActor.props(shardingRegion), "entityCommand"); - actorSystem.actorOf(EntityQueryActor.props(shardingRegion), "entityQuery"); + Cluster.get(actorSystem).registerOnMemberUp(() -> { + ActorRef shardingRegion = setupClusterSharding(actorSystem, httpServer); + createClusterSingletonManagerActor(actorSystem, httpServer); + + actorSystem.actorOf(EntityCommandActor.props(shardingRegion), "entityCommand"); + actorSystem.actorOf(EntityQueryActor.props(shardingRegion), "entityQuery"); + }); addCoordinatedShutdownTask(actorSystem, CoordinatedShutdown.PhaseClusterShutdown());