static async Task Main(string[] args)
    {
        var system        = new ActorSystem();
        var serialization = new Serialization();
        var cluster       = new Cluster(system, serialization);
        var grains        = new Grains(cluster);

        serialization.RegisterFileDescriptor(ProtosReflection.Descriptor);

        await cluster.Start("MyCluster", "node1", 12001, new ConsulProvider(new ConsulProviderOptions(), c => c.Address = new Uri("http://consul:8500/")));

        await Task.Delay(2000);

        var client = grains.HelloGrain("Roger");

        var res = client.SayHello(new HelloRequest()).Result;

        Console.WriteLine(res.Message);


        res = client.SayHello(new HelloRequest()).Result;
        Console.WriteLine(res.Message);
        Console.CancelKeyPress += async(e, y) =>
        {
            Console.WriteLine("Shutting Down...");
            await cluster.Shutdown();
        };
        await Task.Delay(-1);
    }
Beispiel #2
0
        public static void Start()
        {
            var clusterName = "cluster" + DateTime.Now.Ticks;

            StartConsulDevMode();
            Serialization.RegisterFileDescriptor(ProtosReflection.Descriptor);
            Cluster.Start(clusterName, "127.0.0.1", 0, new ConsulProvider(new ConsulProviderOptions()));

            for (int i = 0; i < 30; i++)
            {
                var psi = new ProcessStartInfo("dotnet", "bin/" +
                                               "release" +
                                               "/netcoreapp1.1/TestApp.dll " + clusterName)
                {
                    //   UseShellExecute = false
                };
                Process.Start(psi);
            }
            EventStream.Instance.Subscribe <ClusterTopologyEvent>(e =>
            {
                Console.Write("T");
            });

            var options = new GrainCallOptions()
            {
                RetryCount  = 10,
                RetryAction = async i =>
                {
                    Console.Write("!");
                    i++;
                    await Task.Delay(i *i * 50);
                },
            };

            var tasks = new List <Task>();

            for (int i = 0; i < 20000; i++)
            {
                var client = Grains.HelloGrain("name" + i % 200);
                var task   = client.SayHello(new HelloRequest(), CancellationToken.None, options).ContinueWith(t =>
                {
                    if (t.Status == TaskStatus.RanToCompletion)
                    {
                        Console.Write(".");
                    }
                    else
                    {
                        Console.Write("#");
                    }
                });
                tasks.Add(task);
            }


            Task.WaitAll(tasks.ToArray());
            Console.WriteLine("Done!");
            Console.ReadLine();
        }
        public static async Task Start()
        {
            var log = LoggerFactory.Create(x => x.AddSeq().SetMinimumLevel(LogLevel.Debug));
            Log.SetLoggerFactory(log);

            var logger = log.CreateLogger("Client");

            logger.LogInformation("Test");
            const string clusterName = "test";

            var system = new ActorSystem();
            var serialization = new Serialization();
            var cluster = new Cluster(system, serialization);
            var grains = new Grains(cluster);

            serialization.RegisterFileDescriptor(ProtosReflection.Descriptor);

            await cluster.Start(
                clusterName, "127.0.0.1", 0, new ConsulProvider(new ConsulProviderOptions { DeregisterCritical = TimeSpan.FromSeconds(2) })
            );

            system.EventStream.Subscribe<ClusterTopologyEvent>(e => logger.LogInformation("Topology changed {@Event}", e));
            system.EventStream.Subscribe<MemberStatusEvent>(e => logger.LogInformation("Member status {@Event}", e));

            var options = new GrainCallOptions
            {
                RetryCount = 10,
                RetryAction = i =>
                {
                    Console.Write("!");
                    return Task.Delay(50);
                }
            };

            Console.WriteLine("Ready to send messages, press Enter");
            Console.ReadLine();

            var policy = Policy.Handle<TaskCanceledException>().RetryForeverAsync();

            for (var i = 0; i < 100000; i++)
            {
                var client = grains.HelloGrain("name" + i % 200);

                await policy.ExecuteAsync(
                    () => client.SayHello(new HelloRequest(), CancellationToken.None, options)
                );
                Console.Write(".");
            }

            Console.WriteLine("Done!");
            Console.ReadLine();
            await cluster.Shutdown();
        }
Beispiel #4
0
    static void Main(string[] args)
    {
        Serialization.RegisterFileDescriptor(ProtosReflection.Descriptor);
        Remote.Start("127.0.0.1", 12001);
        Cluster.Start("MyCluster", new ConsulProvider(new ConsulProviderOptions()));

        var client = Grains.HelloGrain("TheName");

        var res = client.SayHello(new HelloRequest()).Result;

        Console.WriteLine(res.Message);
        Console.ReadLine();
    }
Beispiel #5
0
    static void Main(string[] args)
    {
        StartConsulDevMode();
        Serialization.RegisterFileDescriptor(ProtosReflection.Descriptor);

        Cluster.Start("MyCluster", "127.0.0.1", 12001, new ConsulProvider(new ConsulProviderOptions()));

        var client = Grains.HelloGrain("Roger");

        var res = client.SayHello(new HelloRequest()).Result;

        Console.WriteLine(res.Message);
        Console.ReadLine();
        res = client.SayHello(new HelloRequest()).Result;
        Console.WriteLine(res.Message);
        Console.ReadLine();
        Console.WriteLine("Shutting Down...");
        Cluster.Shutdown();
    }
    static async Task Main(string[] args)
    {
        var system = new ActorSystem();

        var remoteConfig = GrpcCoreRemoteConfig
                           .BindToLocalhost(12001)
                           .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);

        await system.Cluster().StartMemberAsync();

        await Task.Delay(2000);

        var grains = new Grains(system.Cluster());
        var client = grains.HelloGrain("Roger");

        var res = await client.SayHello(new HelloRequest());

        Console.WriteLine(res.Message);


        res = await client.SayHello(new HelloRequest());

        Console.WriteLine(res.Message);
        Console.CancelKeyPress += async(e, y) =>
        {
            Console.WriteLine("Shutting Down...");
            await system.Cluster().ShutdownAsync();
        };
        await Task.Delay(-1);
    }
Beispiel #7
0
        private static void Main(string[] args)
        {
            Serialization.RegisterFileDescriptor(ProtosReflection.Descriptor);

            Cluster.Start("BorisNodeTest", "127.0.0.1", 12001, new ConsulProvider(new ConsulProviderOptions()));
            int counter = 300;
            var client  = Grains.HelloGrain("Grain2");

            while (counter < 400)
            {
                var res = client.SayHello((new HelloRequest()
                {
                    Sleep = 100, Count = counter
                })).Result;
                Console.WriteLine(res.Message);
                counter++;
            }
            Thread.Sleep(System.Threading.Timeout.Infinite);
            Console.WriteLine("Shutting Down...");
            Cluster.Shutdown();
        }