コード例 #1
0
ファイル: Startup.cs プロジェクト: cjenp/SmartCacheOrleankka
        private static async Task <IClientActorSystem> StartClientWithRetries()
        {
            // Client config
            IClusterClient client;

            client = new ClientBuilder()
                     .UseLocalhostClustering()
                     .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "nejcSC";
                options.ServiceId = "SmartCache";
            })
                     .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomain).Assembly).WithReferences())
                     .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomainProjection).Assembly).WithReferences())
                     .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomainReader).Assembly).WithReferences())
                     .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomainsInfoProjection).Assembly).WithReferences())
                     .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomainsInfoReader).Assembly).WithReferences())
                     .AddSimpleMessageStreamProvider("SMSProvider")
                     .UseOrleankka()
                     .Build();

            var log = new LoggerConfiguration()
                      .WriteTo.Seq("http://localhost:5341")
                      .WriteTo.Console()
                      .CreateLogger();

            await client.Connect(RetryFilter);

            return(client.ActorSystem());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: gansuranga/Orleankka
        public static async Task Main()
        {
            WriteLine("Running example. Booting cluster might take some time ...\n");

            var host = new SiloHostBuilder()
                       .Configure <ClusterOptions>(options => options.ClusterId         = DemoClusterId)
                       .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(LocalhostSiloAddress, LocalhostSiloPort))
                       .ConfigureEndpoints(LocalhostSiloAddress, LocalhostSiloPort, LocalhostGatewayPort)
                       .ConfigureApplicationParts(x => x
                                                  .AddApplicationPart(Assembly.GetExecutingAssembly())
                                                  .WithCodeGeneration())
                       .UseOrleankka()
                       .Build();

            await host.StartAsync();

            var client = new ClientBuilder()
                         .Configure <ClusterOptions>(options => options.ClusterId = DemoClusterId)
                         .UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(LocalhostSiloAddress, LocalhostGatewayPort).ToGatewayUri()))
                         .ConfigureApplicationParts(x => x
                                                    .AddApplicationPart(Assembly.GetExecutingAssembly())
                                                    .WithCodeGeneration())
                         .UseOrleankka()
                         .Build();

            await client.Connect();

            var greeter = client.ActorSystem().ActorOf <IGreeter>("id");
            await greeter.Tell(new Greet { Who = "world" });

            Write("\n\nPress any key to terminate ...");
            ReadKey(true);
        }
コード例 #3
0
        public static async Task Main()
        {
            WriteLine("Running example. Booting cluster might take some time ...\n");

            var host = new SiloHostBuilder()
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = DemoClusterId;
                options.ServiceId = DemoServiceId;
            })
                       .Configure <SchedulingOptions>(options =>
            {
                options.AllowCallChainReentrancy = false;
            })
                       .Configure <SiloMessagingOptions>(options =>
            {
                options.ResponseTimeout             = TimeSpan.FromSeconds(5);
                options.ResponseTimeoutWithDebugger = TimeSpan.FromSeconds(5);
            })
                       .ConfigureLogging(logging =>
            {
                logging.SetMinimumLevel(LogLevel.Information);
                logging.AddConsole();
            })
                       .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(LocalhostSiloAddress, LocalhostSiloPort))
                       .ConfigureEndpoints(LocalhostSiloAddress, LocalhostSiloPort, LocalhostGatewayPort)
                       .ConfigureApplicationParts(x => x
                                                  .AddApplicationPart(Assembly.GetExecutingAssembly())
                                                  .WithCodeGeneration())
                       .UseOrleankka()
                       .Build();

            await host.StartAsync();

            var client = new ClientBuilder()
                         .Configure <ClusterOptions>(options => {
                options.ClusterId = DemoClusterId;
                options.ServiceId = DemoServiceId;
            })
                         .UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(LocalhostSiloAddress, LocalhostGatewayPort).ToGatewayUri()))
                         .ConfigureApplicationParts(x => x
                                                    .AddApplicationPart(Assembly.GetExecutingAssembly())
                                                    .WithCodeGeneration())
                         .UseOrleankka()
                         .Build();

            await client.Connect();

            var greeter = client.ActorSystem().ActorOf <IGreeter>("id");
            await greeter.Tell(new Greet { Who = "world" });

            Write("\n\nPress any key to terminate ...");
            ReadKey(true);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: stantoxt/Orleankka
        static async Task <IClientActorSystem> Connect(int retries = 0, TimeSpan?retryTimeout = null)
        {
            if (retryTimeout == null)
            {
                retryTimeout = TimeSpan.FromSeconds(5);
            }

            if (retries < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(retries),
                                                      "retries should be greater than or equal to 0");
            }

            while (true)
            {
                try
                {
                    var client = new ClientBuilder()
                                 .Configure <ClusterOptions>(options =>
                    {
                        options.ClusterId = DemoClusterId;
                        options.ServiceId = DemoServiceId;
                    })
                                 .UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(LocalhostSiloAddress, LocalhostGatewayPort).ToGatewayUri()))
                                 .AddSimpleMessageStreamProvider("sms")
                                 .ConfigureServices(x => x
                                                    .AddSingleton <ConnectionToClusterLostHandler>((s, e) => OnClusterConnectionLost()))
                                 .ConfigureApplicationParts(x => x
                                                            .AddApplicationPart(typeof(IChatUser).Assembly)
                                                            .WithCodeGeneration())
                                 .UseOrleankka()
                                 .Build();

                    await client.Connect();

                    return(client.ActorSystem());
                }
                catch (Exception ex)
                {
                    if (retries-- == 0)
                    {
                        Console.WriteLine("Can't connect to cluster. Max retries reached.");
                        throw;
                    }

                    Console.WriteLine($"Can't connect to cluster: '{ex.Message}'. Trying again in {(int)retryTimeout.Value.TotalSeconds} seconds ...");
                    await Task.Delay(retryTimeout.Value);
                }
            }
        }