Exemplo n.º 1
0
        private IClientBuilder UseServiceDiscovery(IClientBuilder build, DownstreamContext context)
        {
            if (context.DownstreamReRoute.DownstreamAddresses.Count > 0)
            {
                List <IPEndPoint> endpoints = new List <IPEndPoint>();
                foreach (var address in context.DownstreamReRoute.DownstreamAddresses)
                {
                    IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(address.Host), address.Port);
                    endpoints.Add(endPoint);
                }
                this._logger.LogDebug($"Orleans uses Static Clustering's ");
                build.UseStaticClustering(endpoints.ToArray());
                return(build);
            }

            //TODO:Determine if it is Consul load balancing
            if (context.Configuration.ServiceProviderConfiguration != null)
            {
                var config = context.Configuration.ServiceProviderConfiguration;
                if (config.Type.Equals("consul", StringComparison.OrdinalIgnoreCase))
                {
                    build.UseConsulClustering(opt =>
                    {
                        opt.Address = new Uri($"http://{config.Host}:{config.Port}");
                        this._logger.LogDebug($"Orleans uses Consul Clustering's address is { opt.Address.ToString()}");
                    });
                    return(build);
                }
                this._logger.LogError($"Does not support {config.Type} service discovery", null);
                throw new OrleansConfigurationException($"Does not support {config.Type} service discovery");
            }

            throw new OrleansConfigurationException($"No service discovery address configured");
        }
Exemplo n.º 2
0
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder
     .UseConsulClustering(gatewayOptions =>
     {
         gatewayOptions.Address = new Uri(ConsulTestUtils.CONSUL_ENDPOINT);
         ;
     });
 }
Exemplo n.º 3
0
        /// <summary>
        /// Configures Consul Clustering.
        /// </summary>
        /// <param name="builder">The Orleans <see cref="IClientBuilder"/>.</param>
        /// <param name="configurationSection">The <see cref="IConfigurationSection"/> which binds to <see cref="ConsulOptions"/>.</param>
        /// <returns>The <see cref="IClientBuilder"/>.</returns>
        public static IClientBuilder ConfigureConsulClustering([NotNull] this IClientBuilder builder, [NotNull] IConfigurationSection configurationSection)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configurationSection?.Exists() != true)
            {
                throw new ConfigurationErrorsException($"Configuration section '{configurationSection?.Path}' is incorrect.");
            }

            var consulOptions = configurationSection.Get <ConsulOptions>() ?? new ConsulOptions();

            return(builder.UseConsulClustering(options =>
            {
                options.Address = new Uri(consulOptions.Address);
                options.KvRootFolder = consulOptions.KvRootFolder;
            }));
        }
 public static IClientBuilder UseConfiguration(
     this IClientBuilder clientBuilder,
     ClientBuilderContext context
     )
 {
     //if (!context.AppInfo.IsDockerized)
     //{
     //	var siloAddress = IPAddress.Loopback;
     //	const int gatewayPort = 30000; // 10400
     //	clientBuilder.UseStaticClustering(new IPEndPoint(siloAddress, gatewayPort));
     //}
     clientBuilder.UseConsulClustering(options =>
     {
         options.Address = new Uri("http://127.0.0.1:8500");
     });
     return(clientBuilder.Configure <ClusterOptions>(config =>
     {
         config.ClusterId = context.ClusterId;
         config.ServiceId = context.ServiceId;
     }));
 }