Пример #1
0
        /// <summary>
        /// Initialize Static Route ClientBuilder
        /// </summary>
        /// <param name="clusterInfo"></param>
        /// <param name="staticGatewayOption"></param>
        /// <param name="applicationPartTypes">Application parts (optional)</param>
        /// <returns></returns>
        public static IClientBuilder CreateStaticRouteClientBuilder(
            ClusterInfoOption clusterInfo,
            StaticGatewayListProviderOptions staticGatewayOption,
            IEnumerable <Type> applicationPartTypes = null)
        {
            var clientBuilder = new ClientBuilder()
                                .ConfigureCluster(clusterInfo, TimeSpan.FromSeconds(20), TimeSpan.FromMinutes(60))
                                .Configure <StatisticsOptions>(options =>
            {
                options.CollectionLevel = StatisticsLevel.Critical;
            })
                                .UseStaticClustering(option =>
            {
                option.Gateways = staticGatewayOption.Gateways;
            });

            if (applicationPartTypes != null)
            {
                clientBuilder.ConfigureApplicationParts(manager =>
                {
                    foreach (var applicationPartType in applicationPartTypes)
                    {
                        manager.AddApplicationPart(applicationPartType.Assembly).WithReferences();
                    }
                });
            }

            return(clientBuilder);
        }
        public async Task DemoRun()
        {
            var clusterInfoOption = new ClusterInfoOption {
                ClusterId = "dev", ServiceId = "HelloWorldApp"
            };
            var staticGatewayOption = new StaticGatewayListProviderOptions
            {
                Gateways = new List <Uri> {
                    new Uri("gwy.tcp://127.0.0.1:30000/0")
                }
            };

            using var client =
                      OrleansClientBuilder.CreateStaticRouteClient(_logger,
                                                                   clusterInfoOption, staticGatewayOption,
                                                                   configureLogging: builder => { builder.AddSerilog(); });

            await client.ConnectWithRetryAsync();

            _logger.LogInformation("Client successfully connect to silo host");

            var grain = client.GetGrain <IHello>(0);

            _logger.LogInformation("Get hello world grain, start calling RPC methods...");

            var returnValue = await grain.SayHello("Hello Orleans");

            _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n");

            await client.Close();

            _logger.LogInformation("Client successfully close connection to silo host");
        }
Пример #3
0
        /// <summary>
        /// Create Orleans Client using static route option
        /// </summary>
        /// <param name="logger">Logger to log ClientBuilder operation information</param>
        /// <param name="clusterInfo"></param>
        /// <param name="staticGatewayOption"></param>
        /// <param name="applicationPartTypes">Application parts (optional)</param>
        /// <param name="configureLogging"></param>
        /// <returns></returns>
        public static IClusterClient CreateStaticRouteClient(ILogger logger,
                                                             ClusterInfoOption clusterInfo,
                                                             StaticGatewayListProviderOptions staticGatewayOption,
                                                             IEnumerable <Type> applicationPartTypes   = null,
                                                             Action <ILoggingBuilder> configureLogging = null)
        {
            try
            {
                var builder = CreateStaticRouteClientBuilder(clusterInfo, staticGatewayOption, applicationPartTypes);
                if (configureLogging != null)
                {
                    builder.ConfigureLogging(configureLogging);
                }

                return(builder.Build());
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Create Silo Client failed");
                throw;
            }
        }
Пример #4
0
 public StaticGatewayListProvider(IOptions <StaticGatewayListProviderOptions> options, IOptions <GatewayOptions> gatewayOptions)
 {
     this.options      = options.Value;
     this.maxStaleness = gatewayOptions.Value.GatewayListRefreshPeriod;
 }
Пример #5
0
 public StaticGatewayListProvider(IOptions <StaticGatewayListProviderOptions> options, ClientConfiguration clientConfiguration)
 {
     this.options      = options.Value;
     this.maxStaleness = clientConfiguration.GatewayListRefreshPeriod;
 }