示例#1
0
        private static async Task <IClusterClient> StartClientWithRetries(int initializeAttemptsBeforeFailing = 5)
        {
            var            siloAddress = IPAddress.Loopback;
            var            gatewayPort = 30000;
            int            attempt     = 0;
            IClusterClient client;

            while (true)
            {
                try
                {
                    client = new ClientBuilder()
                             .ConfigureCluster(options => { options.ClusterId = "helloworldcluster"; })
                             .UseStaticClustering(options => options.Gateways.Add((new IPEndPoint(siloAddress, gatewayPort)).ToGatewayUri()))
                             .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IAccount).Assembly).WithReferences())
                             .ConfigureLogging(logging => logging.AddConsole())
                             .ConfigureServices((servicecollection) =>
                    {
                        SubManager.Parse(servicecollection, typeof(AccountCoreHandler).Assembly);       //注册handle
                        servicecollection.AddSingleton <IOrleansClientFactory, OrleansClientFactory>(); //注册Client获取方法
                        servicecollection.AddSingleton <ISerializer, ProtobufSerializer>();             //注册序列化组件
                        servicecollection.AddRabbitMQ <MessageInfo>();                                  //注册RabbitMq为默认消息队列
                        servicecollection.PostConfigure <RabbitConfig>(c =>
                        {
                            c.UserName    = "******";
                            c.Password    = "******";
                            c.Hosts       = new[] { "127.0.0.1:5672" };
                            c.MaxPoolSize = 100;
                            c.VirtualHost = "/";
                        });
                    })
                             .Build();

                    await client.Connect();

                    OrleansClientFactory.Init(client);
                    Console.WriteLine("Client successfully connect to silo host");
                    break;
                }
                catch (SiloUnavailableException)
                {
                    attempt++;
                    Console.WriteLine($"Attempt {attempt} of {initializeAttemptsBeforeFailing} failed to initialize the Orleans client.");
                    if (attempt > initializeAttemptsBeforeFailing)
                    {
                        throw;
                    }
                    await Task.Delay(TimeSpan.FromSeconds(4));
                }
            }

            return(client);
        }
示例#2
0
        public async Task InitClientAsync()
        {
            var client = OrleansClientFactory.Get(_options);

            await client.Connect();

            _grain = client.GetGrain <TGrain>(Guid.Empty);

            _observerReference = await client.CreateObjectReference <TObServer>(_observer);

            _cancellationToken = new CancellationTokenSource();

            StaySubscribed(_cancellationToken.Token);
        }
示例#3
0
        private static async Task <IClusterClient> StartClientWithRetries(int initializeAttemptsBeforeFailing = 5)
        {
            int            attempt = 0;
            IClusterClient client;

            while (true)
            {
                try
                {
                    client = new ClientBuilder()
                             .UseLocalhostClustering()
                             .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IAccount).Assembly).WithReferences())
                             .ConfigureLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Warning))
                             .ConfigureServices((servicecollection) =>
                    {
                        SubManager.Parse(servicecollection, typeof(AccountToDbHandler).Assembly);       //注册handle
                        servicecollection.AddSingleton <IOrleansClientFactory, OrleansClientFactory>(); //注册Client获取方法
                        servicecollection.AddSingleton <ISerializer, ProtobufSerializer>();             //注册序列化组件
                        servicecollection.AddRabbitMQ <MessageInfo>();                                  //注册RabbitMq为默认消息队列
                        servicecollection.PostConfigure <RabbitConfig>(c =>
                        {
                            c.UserName    = "******";
                            c.Password    = "******";
                            c.Hosts       = new[] { "127.0.0.1:5672" };
                            c.MaxPoolSize = 100;
                            c.VirtualHost = "/";
                        });
                    })
                             .Build();

                    await client.Connect();

                    OrleansClientFactory.Init(client);
                    Console.WriteLine("Client successfully connect to silo host");
                    break;
                }
                catch (SiloUnavailableException)
                {
                    attempt++;
                    Console.WriteLine($"Attempt {attempt} of {initializeAttemptsBeforeFailing} failed to initialize the Orleans client.");
                    if (attempt > initializeAttemptsBeforeFailing)
                    {
                        throw;
                    }
                    await Task.Delay(TimeSpan.FromSeconds(4));
                }
            }

            return(client);
        }
        public async Task <IActionResult> GetOrleansAsync()
        {
            var client = OrleansClientFactory.Get(
                "fabric:/ServiceFabricSample/MyStatelessService",
                "UseDevelopmentStorage=true");

            await client.Connect();

            Console.WriteLine("Connected");

            var grain = client.GetGrain <IMyFirstGrain>(Guid.Parse("26440F3A-D615-4DF9-9E55-A2E740B17C9B"));

            var hello = await grain.SayHello();

            return(Ok(hello));
        }
        public async Task InitClientAsync()
        {
            var client = OrleansClientFactory.Get(
                "fabric:/ServiceFabricSample/MyStatelessService",
                "UseDevelopmentStorage=true");

            await client.Connect();

            Console.WriteLine("Connected");

            _grain = client.GetGrain <IMyFirstGrain>(Guid.Parse("26440F3A-D615-4DF9-9E55-A2E740B17C9B"));

            _observerReference = await client.CreateObjectReference <IHelloObserver>(_observer);

            _cancellationToken = new CancellationTokenSource();
            StaySubscribed(_cancellationToken.Token);
        }
        private static void ConfigureServices(IServiceCollection services,
                                              WebClientFactoryOptions options)
        {
            var orleanOptions = new OrleansClientConnectionOptions
            {
                TableStorageConnectionString = options.FabricSettings.TableStorage,
                ClusterId = options.FabricSettings.IsLocal ? "development" : "production",
                FabricUrl = "fabric:/ServiceFabricSample/MyStatelessService"
            };

            IAppContextSettings contextSettings =
                new AppContextSettings(options.FabricSettings.Db);

            services.AddScoped(provider => OrleansClientFactory.Get(orleanOptions));

            services.AddSingleton(contextSettings);
            services.AddSingleton(options.FabricSettings);
            services.AddSingleton(orleanOptions);
        }
示例#7
0
        private static async Task Run(string[] args)
        {
            Console.WriteLine("Starting....");

            var clientOptions = new OrleansClientConnectionOptions
            {
                ClusterId = "development",
                TableStorageConnectionString = "UseDevelopmentStorage=true",
                FabricUrl = "fabric:/ServiceFabricSample/MyStatelessService"
            };

            var client = OrleansClientFactory.Get(clientOptions);

            Console.WriteLine("Connecting....");

            await client.Connect();


            var grain = client.GetGrain <IMyFirstGrain>(Guid.Empty);

            var subscriber = new OrleansSubscriber(new ClientHelloObserver(), clientOptions);

            await subscriber.InitClientAsync();

            Console.WriteLine("Connected. Type a messge to send. Type quit to exit.");

            string message;

            do
            {
                message = Console.ReadLine();

                if (message != "quit")
                {
                    await grain.ChatAsync(message);
                }
            }while (message != "quit");
        }
示例#8
0
        private static async Task Run(string[] args)
        {
            Console.WriteLine("Starting....");

            var client = OrleansClientFactory.Get(
                "fabric:/ServiceFabricSample/MyStatelessService",
                "UseDevelopmentStorage=true");

            Console.WriteLine("Connecting....");

            await client.Connect();

            Console.WriteLine("Connected");

            var grain = client.GetGrain <IMyFirstGrain>(Guid.Parse("26440F3A-D615-4DF9-9E55-A2E740B17C9B"));

            while (true)
            {
                var hello = await grain.SayHello();

                Console.WriteLine(hello);
                await Task.Delay(TimeSpan.FromSeconds(2));
            }
        }