コード例 #1
0
        static async Task Main(string[] args)
        {
            var system = new ActorSystem();

            var remoteConfig = GrpcCoreRemoteConfig
                               .BindToLocalhost(12000)
                               .WithProtoMessages(ProtosReflection.Descriptor);

            var consulProvider =
                new ConsulProvider(new ConsulProviderConfig(), c => c.Address = new Uri("http://consul:8500/"));

            var clusterConfig =
                ClusterConfig.Setup("MyCluster", consulProvider, new PartitionIdentityLookup());

            system
            .WithRemote(remoteConfig)
            .WithCluster(clusterConfig);

            var grains = new Grains(system.Cluster());

            grains.HelloGrainFactory(() => new HelloGrain());

            await system.Cluster().StartMemberAsync();

            Console.CancelKeyPress += async(e, y) =>
            {
                Console.WriteLine("Shutting Down...");
                await system.Cluster().ShutdownAsync();
            };
            await Task.Delay(-1);
        }
コード例 #2
0
    private static async Task Main()
    {
        var system = new ActorSystem()
                     .WithRemote(GrpcCoreRemoteConfig
                                 .BindToLocalhost()
                                 .WithProtoMessages(ProtosReflection.Descriptor))
                     .WithCluster(ClusterConfig
                                  .Setup("MyCluster", new ConsulProvider(new ConsulProviderConfig()), new PartitionIdentityLookup()));

        await system
        .Cluster()
        .StartClientAsync();

        Console.WriteLine("Started");
        await Task.Delay(2000);


        var helloGrain = system.Cluster().GetHelloGrain("MyGrain");

        var res = await helloGrain.SayHello(new HelloRequest(), WithTimeout(5000));

        Console.WriteLine(res.Message);

        res = await helloGrain.SayHello(new HelloRequest(), WithTimeout(5000));

        Console.WriteLine(res.Message);

        Console.CancelKeyPress += async(e, y) => {
            Console.WriteLine("Shutting Down...");
            await system.Cluster().ShutdownAsync();
        };

        await Task.Delay(-1);
    }
            public Fixture()
            {
                var clientConfig = ConfigureClientRemoteConfig(GrpcCoreRemoteConfig.BindToLocalhost(5000));

                Remote = GetGrpcCoreRemote(clientConfig);
                var serverConfig = ConfigureServerRemoteConfig(GrpcCoreRemoteConfig.BindToLocalhost(5001));

                ServerRemote = GetGrpcCoreRemote(serverConfig);
            }
コード例 #4
0
        static async Task Main(string[] args)
        {
            var log = LoggerFactory.Create(x => x.AddConsole().SetMinimumLevel(LogLevel.Debug));

            Log.SetLoggerFactory(log);
            Console.WriteLine("Starting Node2");

            var system        = new ActorSystem();
            var serialization = new Serialization();
            var context       = new RootContext(system);

            serialization.RegisterFileDescriptor(ProtosReflection.Descriptor);


            var props = Props.FromFunc(
                ctx =>
            {
                switch (ctx.Message)
                {
                case HelloRequest _:
                    ctx.Respond(new HelloResponse {
                        Message = "Hello from node 2"
                    });
                    break;
                }

                return(Task.CompletedTask);
            }
                );


            var remoteConfig = GrpcCoreRemoteConfig
                               .BindToLocalhost(12001)
                               .WithProtoMessages(ProtosReflection.Descriptor);

            var clusterConfig = ClusterConfig.Setup("MyCluster",
                                                    new ConsulProvider(new ConsulProviderConfig(), c => c.Address = new Uri("http://consul:8500/")),
                                                    new PartitionIdentityLookup()
                                                    ).WithClusterKind("HelloKind", props);

            system
            .WithRemote(remoteConfig)
            .WithCluster(clusterConfig);


            // CONSUL
            await system
            .Cluster()
            .StartMemberAsync();

            await Task.Delay(-1);

            Console.WriteLine("Shutting Down...");
            await system
            .Cluster()
            .ShutdownAsync();
        }
コード例 #5
0
        public void CanRegisterKind()
        {
            var props  = new Props();
            var kind   = Guid.NewGuid().ToString();
            var remote = new GrpcCoreRemote(new ActorSystem(),
                                            GrpcCoreRemoteConfig.BindToLocalhost()
                                            .WithRemoteKinds((kind, props))
                                            );

            Assert.Equal(props, remote.Config.GetRemoteKind(kind));
        }
コード例 #6
0
    static async Task Main(string[] args)
    {
        var system  = new ActorSystem();
        var context = new RootContext(system);

        //Registering "knownTypes" is not required, but improves performance as those messages
        //do not need to pass any typename manifest


        var remoteConfig = GrpcCoreRemoteConfig.BindToLocalhost(12001);

        system.WithRemote(remoteConfig);
        var wire = new WireSerializer(new[] { typeof(Ping), typeof(Pong), typeof(StartRemote), typeof(Start) });

        system.Serialization().RegisterSerializer(wire, true);
        await system.Remote().StartAsync();

        var messageCount = 1000000;
        var wg           = new AutoResetEvent(false);
        var props        = Props.FromProducer(() => new LocalActor(0, messageCount, wg));

        var pid       = context.Spawn(props);
        var remotePid = new PID("127.0.0.1:12000", "remote");

        context.RequestAsync <Start>(remotePid, new StartRemote {
            Sender = pid
        }).Wait();

        var start = DateTime.Now;

        Console.WriteLine("Starting to send");
        var msg = new Ping();

        for (var i = 0; i < messageCount; i++)
        {
            context.Send(remotePid, msg);
        }
        wg.WaitOne();
        var elapsed = DateTime.Now - start;

        Console.WriteLine("Elapsed {0}", elapsed);

        var t = messageCount * 2.0 / elapsed.TotalMilliseconds * 1000;

        Console.WriteLine("Throughput {0} msg / sec", t);

        Console.ReadLine();
    }
コード例 #7
0
        static async Task Main(string[] args)
        {
            var log = LoggerFactory.Create(x => x.AddConsole().SetMinimumLevel(LogLevel.Debug));

            Log.SetLoggerFactory(log);

            Console.WriteLine("Starting Node1");
            var system = new ActorSystem();

            var context = new RootContext(system);

            var remoteConfig = GrpcCoreRemoteConfig
                               .BindToLocalhost(12000)
                               .WithProtoMessages(ProtosReflection.Descriptor);

            var clusterConfig = ClusterConfig.Setup("MyCluster",
                                                    new ConsulProvider(new ConsulProviderConfig(), c => c.Address = new Uri("http://consul:8500/")),
                                                    new PartitionIdentityLookup()
                                                    );

            system
            .WithRemote(remoteConfig)
            .WithCluster(clusterConfig);

            // CONSUL

            await system
            .Cluster()
            .StartMemberAsync();

            var i = 10000;

            while (i-- > 0)
            {
                var res = await system
                          .Cluster()
                          .RequestAsync <HelloResponse>("TheName", "HelloKind", new HelloRequest(), CancellationToken.None);

                Console.WriteLine(res.Message);
                await Task.Delay(500);
            }

            await Task.Delay(-1);

            Console.WriteLine("Shutting Down...");

            await system.Cluster().ShutdownAsync();
        }
コード例 #8
0
        public void CanRegisterMultipleKinds()
        {
            var props  = new Props();
            var kind1  = Guid.NewGuid().ToString();
            var kind2  = Guid.NewGuid().ToString();
            var remote = new GrpcCoreRemote(new ActorSystem(),
                                            GrpcCoreRemoteConfig
                                            .BindToLocalhost()
                                            .WithRemoteKinds(
                                                (kind1, props),
                                                (kind2, props)
                                                )
                                            );

            var kinds = remote.Config.GetRemoteKinds();

            Assert.Contains(kind1, kinds);
            Assert.Contains(kind2, kinds);
        }
コード例 #9
0
        private static async Task Main()
        {
            var remoteConfig = GrpcCoreRemoteConfig
                               .BindToLocalhost()
                               .WithProtoMessages(ProtosReflection.Descriptor);

            var consulProvider =
                new ConsulProvider(new ConsulProviderConfig(), c => c.Address = new Uri("http://consul:8500/"));

            var clusterConfig =
                ClusterConfig
                .Setup("MyCluster", consulProvider, new PartitionIdentityLookup());

            var system = new ActorSystem()
                         .WithRemote(remoteConfig)
                         .WithCluster(clusterConfig);

            await system
            .Cluster()
            .StartMemberAsync();

            //subscribe to the eventstream via type, just like you do locally
            system.EventStream.SubscribeToTopic <SomeMessage>("MyTopic.*", x => Console.WriteLine($"Got message for {x.Name}"));

            //publish messages onto the eventstream on Subtopic1 on MyTopic root
            //but do this using cluster broadcasting. this will publish the event
            //to the event stream on all the members in the cluster
            //this is best effort only, if some member is unavailable, there is no guarantee associated here
            system.Cluster().BroadcastEvent(new SomeMessage("ProtoActor", "MyTopic.Subtopic1"));

            //this message is published on a topic that is not subscribed to, and nothing will happen
            system.Cluster().BroadcastEvent(new SomeMessage("Asynkron", "AnotherTopic"));

            //send a message to the same root topic, but another child topic
            system.Cluster().BroadcastEvent(new SomeMessage("Do we get this?", "MyTopic.Subtopic1"));

            //this example is local only.
            //see ClusterEventStream for cluster broadcast onto the eventstream

            Console.ReadLine();
        }
コード例 #10
0
        public void UnknownKindThrowsException()
        {
            var remote = new GrpcCoreRemote(new ActorSystem(), GrpcCoreRemoteConfig.BindToLocalhost());

            Assert.Throws <ArgumentException>(() => { remote.Config.GetRemoteKind("not registered"); });
        }
コード例 #11
0
        public static void Run()
        {
            var l = LoggerFactory.Create(x => x.AddConsole().SetMinimumLevel(LogLevel.Information));

            Log.SetLoggerFactory(l);
            var config = ActorSystemConfig.Setup().WithMetricsProviders(new PrometheusConfigurator());

            var remoteConfig = GrpcCoreRemoteConfig
                               .BindToLocalhost()
                               .WithProtoMessages(MessagesReflection.Descriptor);

            var clusterConfig =
                ClusterConfig
                .Setup("MyCluster", new ConsulProvider(new ConsulProviderConfig(), c => c.Address = new Uri("http://127.0.0.1:8500/")),
                       new PartitionIdentityLookup()
                       );

            var system = new ActorSystem(config)
                         .WithRemote(remoteConfig)
                         .WithCluster(clusterConfig);

            system
            .Cluster()
            .StartMemberAsync();

            var props = Props.FromProducer(() => new MyActor());

            var config2 = ActorSystemConfig.Setup().WithMetricsProviders(new PrometheusConfigurator());

            var remoteConfig2 = GrpcCoreRemoteConfig
                                .BindToLocalhost()
                                .WithProtoMessages(MessagesReflection.Descriptor);

            var clusterConfig2 =
                ClusterConfig
                .Setup("MyCluster", new ConsulProvider(new ConsulProviderConfig(), c => c.Address = new Uri("http://127.0.0.1:8500/")),
                       new PartitionIdentityLookup()
                       )
                .WithClusterKind("somekind", props);

            var system2 = new ActorSystem(config2)
                          .WithRemote(remoteConfig2)
                          .WithCluster(clusterConfig2);

            system2
            .Cluster()
            .StartMemberAsync();

            _ = SafeTask.Run(async() => {
                var r = new Random();

                while (true)
                {
                    await Task.Delay(r.Next(1, 2000));
                    await system.Cluster().RequestAsync <SomeResponse>($"someactor{r.Next(1, 100)}", "somekind", new SomeRequest(),
                                                                       CancellationTokens.WithTimeout(5000)
                                                                       );
                }
            }
                             );
        }
コード例 #12
0
 private static GrpcCoreRemoteConfig GetRemoteConfig() => GrpcCoreRemoteConfig
 .BindToLocalhost()
 .WithProtoMessages(ClusterPubSub.ProtosReflection.Descriptor);