public ServiceActor(int id) { _id = id; _log = Context.GetLogger(); Receive <Ping>(ping => { _log.Info($"Received ping from {ping.Sender}"); ping.Sender.Tell(new Pong($"From {Util.ActorName(id)}: {ping.Payload} PONG!")); }); }
public async Task StartAsync() { var setup = ActorSystemSetup.Create( BootstrapSetup.Create() .WithConfig(Util.Config(_port)) .WithConfigFallback(DistributedPubSub.DefaultConfig()) .WithConfigFallback(ClusterClientReceptionist.DefaultConfig()) .WithActorRefProvider(ProviderSelection.Cluster.Instance)); _actorSystem = ActorSystem.Create(Consts.NodeName, setup); var cluster = Akka.Cluster.Cluster.Get(_actorSystem); await cluster.JoinSeedNodesAsync(Consts.Seeds); _receptionist = ClusterClientReceptionist.Get(_actorSystem); foreach (var id in Enumerable.Range(_nodeId * Consts.ActorCount, Consts.ActorCount)) { var actor = _actorSystem.ActorOf(Props.Create(() => new ServiceActor(id)), Util.ActorName(id)); _receptionist.RegisterService(actor); } }