Пример #1
0
        private static IConveyBuilder AddServiceClient <T>(this IConveyBuilder builder, string serviceName,
                                                           RestEaseOptions options, Action <IConveyBuilder> registerFabio)
            where T : class
        {
            if (!builder.TryRegister(RegistryName))
            {
                return(builder);
            }

            var clientName = typeof(T).ToString();

            switch (options.LoadBalancer?.ToLowerInvariant())
            {
            case "consul":
                builder.AddConsulHttpClient(clientName, serviceName);
                break;

            case "fabio":
                builder.AddFabioHttpClient(clientName, serviceName);
                break;

            default:
                ConfigureDefaultClient(builder.Services, clientName, serviceName, options);
                break;
            }

            ConfigureForwarder <T>(builder.Services, clientName);

            registerFabio(builder);

            return(builder);
        }
Пример #2
0
        private static void ConfigureDefaultClient(IServiceCollection services, string clientName,
                                                   string serviceName, RestEaseOptions options)
        {
            services.AddHttpClient(clientName, client =>
            {
                var service = options.Services.SingleOrDefault(s => s.Name.Equals(serviceName,
                                                                                  StringComparison.InvariantCultureIgnoreCase));
                if (service == null)
                {
                    throw new RestEaseServiceNotFoundException($"RestEase service: '{serviceName}' was not found.",
                                                               serviceName);
                }

                client.BaseAddress = new UriBuilder
                {
                    Scheme = service.Scheme,
                    Host   = service.Host,
                    Port   = service.Port
                }.Uri;
            });
        }
Пример #3
0
 public static IConveyBuilder AddServiceClient <T>(this IConveyBuilder builder, string serviceName,
                                                   RestEaseOptions options, ConsulOptions consulOptions, FabioOptions fabioOptions,
                                                   HttpClientOptions httpClientOptions)
     where T : class
 => builder.AddServiceClient <T>(serviceName, options,
                                 b => b.AddFabio(fabioOptions, consulOptions, httpClientOptions));