コード例 #1
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            cluster = Akka.Cluster.Cluster.Get(this.actorSystem);

            cluster.RegisterOnMemberUp(() => {
                var foorouter = actorSystem.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "PubActor");


                int i = 0;
                this.actorSystem.Scheduler.Advanced.ScheduleRepeatedly(TimeSpan.Zero, TimeSpan.FromMilliseconds(1000), () => {
                    i++;
                    foorouter.Ask <HelloResponse>(new Hello(i.ToString()))
                    .ContinueWith(tr => {
                        if (tr.IsCompletedSuccessfully)
                        {
                            Console.WriteLine($"Response:{tr.Result?.Message}");
                        }
                    });
                });
            });

            cluster.RegisterOnMemberUp(() => {
            });


            return(base.StartAsync(cancellationToken));
        }
コード例 #2
0
        public static async Task StartAsync <TStartup>(CancellationToken cancellationToken)
            where TStartup : MicroserviceStartup, new()
        {
            actorSystem = StartInternal <TStartup>();
            cluster     = Akka.Cluster.Cluster.Get(actorSystem);

            cluster.RegisterOnMemberUp(() =>
            {
                IsClustered = true;
            });

            cluster.RegisterOnMemberRemoved(() =>
            {
                if (IsClustered)
                {
                    IsClustered = false;
                    ClusterLeaveEvent.Set();
                }
            });

            await Task.Delay(TimeSpan.FromMilliseconds(-1), cancellationToken);

            if (IsClustered)
            {
                cluster.Leave(cluster.SelfAddress);

                if (!ClusterLeaveEvent.WaitHandle.WaitOne(10.Seconds()))
                {
                    cluster.Down(cluster.SelfAddress);
                }
            }

            await actorSystem.Terminate();
        }
コード例 #3
0
        public virtual void Start()
        {
            _actorSystem = ActorSystem.Create(Name, _config);

            _cluster = Akka.Cluster.Cluster.Get(_actorSystem);

            BuildActorSystem();

            Console.WriteLine("Started");
        }
コード例 #4
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            cluster = Akka.Cluster.Cluster.Get(actorSystem);

            cluster.RegisterOnMemberUp(RegisterOnMemberUp);

            cluster.RegisterOnMemberRemoved(RegisterOnMemberRemoved);

            return(base.StartAsync(cancellationToken));
        }
コード例 #5
0
        public override async Task StartAsync(CancellationToken cancellationToken)
        {

            cluster = Akka.Cluster.Cluster.Get(ActorSystem);

            cluster.RegisterOnMemberUp(RegisterOnMemberUp);

            cluster.RegisterOnMemberRemoved(RegisterOnMemberRemoved);
            ClusterDiscovery.Get(ActorSystem);
           

            await ClusterDiscovery.JoinAsync(ActorSystem);
           
        }
コード例 #6
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            cluster = Akka.Cluster.Cluster.Get(this.actorSystem);

            cluster.RegisterOnMemberUp(() => {
                ;
                var foo = actorSystem.ActorOf(FooActor.Props(), "FooActor");

                var artileServer = actorSystem.ActorOf(ArticleWorkerActor.For(actorSystem), "artileServer");
            });



            return(base.StartAsync(cancellationToken));
        }
コード例 #7
0
ファイル: Worker.cs プロジェクト: fzf003/dotnet-akka-lab
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            cluster = Akka.Cluster.Cluster.Get(this.actorSystem);

            cluster.RegisterOnMemberUp(() => {
                var foorouter = actorSystem.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "PubActor");
                this._clusterProxy.ClusterClient = foorouter;

                var articlecient = actorSystem.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "artileClient");
                this._clusterProxy.ArtileClient = articlecient;

                this.logger.LogInformation("иооъ:{0}", foorouter.Path.Address.ToString());
                this.logger.LogInformation("иооъ:{0}", articlecient.Path.Address.ToString());
            });



            return(base.StartAsync(cancellationToken));
        }
コード例 #8
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            cluster = Akka.Cluster.Cluster.Get(this.actorSystem);

            cluster.RegisterOnMemberUp(() => {
                clientserviceref = actorSystem.ActorOf(Props.Create(() => new ClientService(IPAddress.Parse("127.0.0.1"), 9001)), "echo-client");

                actorSystem.Scheduler.Advanced.ScheduleRepeatedly(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), () =>
                {
                    clientserviceref.Tell(new SendMessage($"{DateTime.Now.ToString()}--{Guid.NewGuid().ToString("N")}\n"));
                });
            });

            cluster.RegisterOnMemberRemoved(() =>
            {
                clientserviceref.Tell(StopMessage.Instance);
            });


            return(base.StartAsync(cancellationToken));
        }
コード例 #9
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            cluster = Akka.Cluster.Cluster.Get(this.actorSystem);

            cluster.RegisterOnMemberUp(() => {
                listenerechoserice = actorSystem.ActorOf(Props.Create(() => new EchoService(new IPEndPoint(IPAddress.Any, 9001))), "echo-service");
            });

            cluster.RegisterOnMemberRemoved(() => {
                listenerechoserice.Ask(EchoService.StopServer.Instance)
                .ContinueWith(t =>
                {
                    if (t.IsCompletedSuccessfully)
                    {
                        Console.WriteLine($"服务已停止:{t.Result}");
                    }
                }).ConfigureAwait(false);
            });


            return(base.StartAsync(cancellationToken));
        }
コード例 #10
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            cluster = Akka.Cluster.Cluster.Get(ActorSystem);

            return(base.StartAsync(cancellationToken));
        }