Exemple #1
0
        public ConsulClient(ConsulClientConfiguration config)
        {
            config.Updated += HandleConfigUpdateEvent;
            var ctr = new ConsulClientConfigurationContainer(config);

            ApplyConfig(ctr.Config, ctr.HttpHandler, ctr.HttpClient);

            ConfigContainer = ctr;
            InitializeEndpoints();
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new Consul client with the configuration specified and a custom HttpClient, which is useful for setting proxies/custom timeouts.
        /// The HttpClient must accept the "application/json" content type and the Timeout property should be set to at least 15 minutes to allow for blocking queries.
        /// </summary>
        /// <param name="config">A Consul client configuration</param>
        /// <param name="client">A custom HttpClient. The lifetime, including disposal, of this HttpClient is not handled by ConsulClient</param>
        public ConsulClient(ConsulClientConfiguration config, HttpClient client)
        {
            var ctr = new ConsulClientConfigurationContainer(config, client);

            if (!ctr.HttpClient.DefaultRequestHeaders.Accept.Contains(new MediaTypeWithQualityHeaderValue("application/json")))
            {
                throw new ArgumentException("HttpClient must accept the application/json content type", nameof(client));
            }
            ConfigContainer = ctr;
            InitializeEndpoints();
        }
Exemple #3
0
        public ConsulClient(Action <ConsulClientConfiguration> configOverride, Action <HttpClient> clientOverride, Action <HttpClientHandler> handlerOverride)
#endif
        {
            var ctr = new ConsulClientConfigurationContainer();

            configOverride?.Invoke(ctr.Config);
            ApplyConfig(ctr.Config, ctr.HttpHandler, ctr.HttpClient);
            handlerOverride?.Invoke(ctr.HttpHandler);
            clientOverride?.Invoke(ctr.HttpClient);

            ConfigContainer = ctr;

            InitializeEndpoints();
        }