示例#1
0
        public static HttpClient CreateClient(IConsulAclProvider aclProvider, string agentHost = null, int?agentPort = null)
        {
            var host = agentHost ?? DefaultHost;
            var port = agentPort ?? DefaultPort;

            var        uri = new UriBuilder("http", host, port);
            HttpClient client;

#if NET452
            System.Net.ServicePointManager.DefaultConnectionLimit = 50;
            client = new HttpClient()
            {
                BaseAddress = uri.Uri,
                Timeout     = DefaultTimeout
            };
#else
            client = new HttpClient(new HttpClientHandler()
            {
                MaxConnectionsPerServer = 50
            })
            {
                BaseAddress = uri.Uri,
                Timeout     = DefaultTimeout
            };
#endif
            var token = aclProvider?.GetAclToken();
            if (!string.IsNullOrEmpty(token))
            {
                client.DefaultRequestHeaders.Add("X-Consul-Token", token);
            }
            return(client);
        }
        public ConsulRouteSource(CondenserConfiguration config,
                                 ILoggerFactory logger, IConsulAclProvider aclProvider = null)
        {
            _client           = HttpUtils.CreateClient(aclProvider, config.AgentAddress, config.AgentPort);
            _healthCheckUri   = $"{HttpUtils.HealthAnyUrl}?index=";
            _serviceLookupUri = $"{HttpUtils.SingleServiceCatalogUrl}";

            _logger = logger?.CreateLogger <ConsulRouteSource>();
        }
        public static HttpClient CreateClient(IConsulAclProvider aclProvider, string agentHost = null, int?agentPort = null)
        {
            CondenserEventSource.Log.HttpClientCreated();
            var host = agentHost ?? DefaultHost;
            var port = agentPort ?? DefaultPort;

            var uri    = new UriBuilder("http", host, port);
            var client = new HttpClient(new HttpClientHandler()
            {
                MaxConnectionsPerServer = 50
            })
            {
                BaseAddress = uri.Uri,
                Timeout     = DefaultTimeout
            };
            var token = aclProvider?.GetAclToken();

            if (!string.IsNullOrEmpty(token))
            {
                client.DefaultRequestHeaders.Add("X-Consul-Token", token);
            }
            return(client);
        }
示例#4
0
        public ServiceManager(IOptions <ServiceManagerConfig> optionsConfig, Func <HttpClient> httpClientFactory = null, ILoggerFactory logFactory = null, IServer server = null, IConsulAclProvider aclProvider = null)
        {
            if (optionsConfig.Value.ServicePort == 0 && server == null)
            {
                throw new ArgumentOutOfRangeException($"A valid server port needs to be set through either the options or the hosting server");
            }

            var config = optionsConfig.Value;

            Logger = logFactory?.CreateLogger <ServiceManager>();
            Client = httpClientFactory?.Invoke() ?? HttpUtils.CreateClient(aclProvider);
            config.SetDefaults(server);
            ServiceId      = config.ServiceId;
            ServiceName    = config.ServiceName;
            ServiceAddress = config.ServiceAddress;
            ServicePort    = config.ServicePort;
        }
        public ConsulConfigSource(IOptions <ConsulRegistryConfig> agentConfig, ILogger logger, IConsulAclProvider aclProvider)
        {
            _logger = logger;
            var agentInfo = agentConfig?.Value ?? new ConsulRegistryConfig();

            _parser = agentInfo.KeyParser;

            CondenserEventSource.Log.ConfigurationHttpClientCreated();
            _httpClient = HttpUtils.CreateClient(aclProvider, agentInfo.AgentAddress, agentInfo.AgentPort);
        }
 public ServiceRegistry(Func <HttpClient> httpClientFactory = null, ILoggerFactory loggerFactory = null, IConsulAclProvider aclProvider = null)
 {
     _logger = loggerFactory?.CreateLogger <ServiceRegistry>();
     _client = httpClientFactory?.Invoke() ?? HttpUtils.CreateClient(aclProvider);
 }