sequence

This article focuses on the parameters of JerseyEurekaHttpClient

JerseyEurekaHttpClientFactory

Eureka – the client – 1.8.8 – sources jar! /com/netflix/discovery/shared/transport/jersey/JerseyEurekaHttpClientFactory.java

        private JerseyEurekaHttpClientFactory buildLegacy(Map<String, String> additionalHeaders, boolean systemSSL) {
            EurekaJerseyClientBuilder clientBuilder = new EurekaJerseyClientBuilder()
                    .withClientName(clientName)
                    .withUserAgent("Java-EurekaClient")
                    .withConnectionTimeout(connectionTimeout)
                    .withReadTimeout(readTimeout)
                    .withMaxConnectionsPerHost(maxConnectionsPerHost)
                    .withMaxTotalConnections(maxTotalConnections)
                    .withConnectionIdleTimeout((int) connectionIdleTimeout)
                    .withEncoderWrapper(encoderWrapper)
                    .withDecoderWrapper(decoderWrapper);

            if (systemSSL) {
                clientBuilder.withSystemSSLConfiguration();
            } else if(sslContext ! = null) { clientBuilder.withCustomSSL(sslContext); }if(hostnameVerifier ! = null) { clientBuilder.withHostnameVerifier(hostnameVerifier); } EurekaJerseyClient jerseyClient = clientBuilder.build(); ApacheHttpClient4 discoveryApacheClient = jerseyClient.getClient(); addFilters(discoveryApacheClient);return new JerseyEurekaHttpClientFactory(jerseyClient, additionalHeaders);
        }
Copy the code

ConnectionTimeout, readTimeout, maxConnectionsPerHost, maxTotalConnections, connectionIdleTimeout.

EurekaJerseyClientImpl

Eureka – the client – 1.8.8 – sources jar! /com/netflix/discovery/shared/transport/jersey/EurekaJerseyClientImpl.java

    public EurekaJerseyClientImpl(int connectionTimeout, int readTimeout, final int connectionIdleTimeout,
                                  ClientConfig clientConfig) {
        try {
            jerseyClientConfig = clientConfig;
            apacheHttpClient = ApacheHttpClient4.create(jerseyClientConfig);
            HttpParams params = apacheHttpClient.getClientHandler().getHttpClient().getParams();

            HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
            HttpConnectionParams.setSoTimeout(params, readTimeout); this.apacheHttpClientConnectionCleaner = new ApacheHttpClientConnectionCleaner(apacheHttpClient, connectionIdleTimeout);  } catch (Throwable e) { throw new RuntimeException("Cannot create Jersey client", e);
        }
    }
    
    public EurekaJerseyClient build() {
            MyDefaultApacheHttpClient4Config config = new MyDefaultApacheHttpClient4Config();
            try {
                return new EurekaJerseyClientImpl(connectionTimeout, readTimeout, connectionIdleTimeout, config);
            } catch (Throwable e) {
                throw new RuntimeException("Cannot create Jersey client ", e);
            }
        }

        class MyDefaultApacheHttpClient4Config extends DefaultApacheHttpClient4Config {
            MyDefaultApacheHttpClient4Config() {
                MonitoredConnectionManager cm;

                if (systemSSL) {
                    cm = createSystemSslCM();
                } else if(sslContext ! = null || hostnameVerifier ! = null || trustStoreFileName ! = null) { cm = createCustomSslCM(); }else {
                    cm = createDefaultSslCM();
                }

                if(proxyHost ! = null) { addProxyConfiguration(cm); } DiscoveryJerseyProvider discoveryJerseyProvider = new DiscoveryJerseyProvider(encoderWrapper, decoderWrapper); getSingletons().add(discoveryJerseyProvider); // Common properties to all clients cm.setDefaultMaxPerRoute(maxConnectionsPerHost); cm.setMaxTotal(maxTotalConnections); getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, cm); String fullUserAgentName = (userAgent == null ? clientName : userAgent) +"/v" + buildVersion();
                getProperties().put(CoreProtocolPNames.USER_AGENT, fullUserAgentName);

                // To pin a client to specific server in caseredirect happens, we handle redirects directly // (see DiscoveryClient.makeRemoteCall methods). getProperties().put(PROPERTY_FOLLOW_REDIRECTS, Boolean.FALSE); getProperties().put(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE); } / /... }Copy the code

One can see maxConnectionsPerHost and maxTotalConnections is configured in the MonitoredConnectionManager; ConnectionTimeout, readTimeout, and connectionIdleTimeout are configured on HttpConnectionParams of the Apache HTTP Client.

Parameter configuration

Eureka – the client – 1.8.8 – sources jar! /com/netflix/discovery/shared/transport/EurekaClientFactoryBuilder.java

    public B withClientConfig(EurekaClientConfig clientConfig) {
        withClientAccept(EurekaAccept.fromString(clientConfig.getClientDataAccept()));
        withAllowRedirect(clientConfig.allowRedirects());
        withConnectionTimeout(clientConfig.getEurekaServerConnectTimeoutSeconds() * 1000);
        withReadTimeout(clientConfig.getEurekaServerReadTimeoutSeconds() * 1000);
        withMaxConnectionsPerHost(clientConfig.getEurekaServerTotalConnectionsPerHost());
        withMaxTotalConnections(clientConfig.getEurekaServerTotalConnections());
        withConnectionIdleTimeout(clientConfig.getEurekaConnectionIdleTimeoutSeconds() * 1000);
        withEncoder(clientConfig.getEncoderName());
        return withDecoder(clientConfig.getDecoderName(), clientConfig.getClientDataAccept());
    }
Copy the code

You can see that this is read from EurekaClientConfig and its mapping is as follows:

attribute configuration The default value instructions
connectionTimeout eureka.client.eureka-server-connect-timeout-seconds 5 Indicates how long to wait (in seconds) before a connection to eureka server needs to timeout. Note that the connections in the client are pooled by org.apache.http.client.HttpClient and this setting affects the actual connection creation and also the wait time to get the connection from the pool.
readTimeout eureka.client.eureka-server-read-timeout-seconds 8 Indicates how long to wait (in seconds) before a read from eureka server needs to timeout.
maxConnectionsPerHost eureka.client.eureka-server-total-connections-per-host 50 Gets the total number of connections that is allowed from eureka client to a eureka server host.
maxTotalConnections eureka.client.eureka-server-total-connections 200 Gets the total number of connections that is allowed from eureka client to all eureka servers.
connectionIdleTimeout eureka.client.eureka-connection-idle-timeout-seconds 30 Indicates how much time (in seconds) that the HTTP connections to eureka server can stay idle before it can be closed. In the AWS environment, it is recommended that the values is 30 seconds or less, since the firewall cleans up the connection information after a few mins leaving the connection hanging in limbo

summary

The value can be eureka-server-connect-timeout-seconds, eureka-server-read-timeout-seconds, eureka-server-totals-connections-per-host, or eu Reka-server-total-connections and eureka-connection-idle-timeout-seconds are used to configure and manage HTTP connections between the Eureka client and the Eureka server.

doc

  • EurekaJerseyClientImpl