Skip to content

Commit

Permalink
Merge branch 'main' into feature/3685
Browse files Browse the repository at this point in the history
# Conflicts:
#	docs/modules/ROOT/partials/_configprops.adoc
  • Loading branch information
heowc committed Apr 17, 2024
2 parents 811c04f + 2a8b7ed commit de2ea96
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 66 deletions.
11 changes: 0 additions & 11 deletions docs/modules/ROOT/pages/spring-cloud-netflix.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,6 @@ eureka:
socket-timeout: 10000
----

When using the default Apache HTTP Client Request Factory, an additional parameter can be used to configure timeout for evicting idle connections. Default value is 30 seconds. Value must be specified in milliseconds.

.application.yml
[source,yaml]
----
eureka:
client:
rest-template-timeout:
idle-timeout: 30000
----

=== Status Page and Health Indicator

The status page and health indicators for a Eureka instance default to `/info` and `/health` respectively, which are the default locations of useful endpoints in a Spring Boot Actuator application.
Expand Down
1 change: 0 additions & 1 deletion docs/modules/ROOT/partials/_configprops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
|eureka.client.registry-refresh-single-vip-address | | Indicates whether the client is only interested in the registry information for a single VIP.
|eureka.client.rest-template-timeout.connect-request-timeout | `+++0+++` |
|eureka.client.rest-template-timeout.connect-timeout | `+++0+++` | Default values are set to 180000, in keeping with {@link RequestConfig} and {@link SocketConfig} defaults.
|eureka.client.rest-template-timeout.idle-timeout | `+++0+++` | Indicates how long a connection can be idle before it is evicted from the connection pool.
|eureka.client.rest-template-timeout.socket-timeout | `+++0+++` |
|eureka.client.service-url | | Map of availability zone to list of fully qualified URLs to communicate with eureka server. Each value can be a single URL or a comma separated list of alternative locations. Typically the eureka server URLs carry protocol,host,port,context and version information if any. Example: https://ec2-256-156-243-129.compute-1.amazonaws.com:7001/eureka/ The changes are effective at runtime at the next service url refresh cycle as specified by eurekaServiceUrlPollIntervalSeconds.
|eureka.client.should-enforce-registration-at-init | `+++false+++` | Indicates whether the client should enforce registration during initialization. Defaults to false.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 the original author or authors.
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,6 @@
* {@link RestTemplateEurekaHttpClient}.
*
* @author Jiwon Jeon
* @author Armin Krezovic
* @since 3.1.6
*/
@ConfigurationProperties("eureka.client.rest-template-timeout")
Expand All @@ -46,12 +45,6 @@ public class RestTemplateTimeoutProperties {

private int socketTimeout = 3 * 60 * 1000;

/**
* Indicates how long a connection can be idle before it is evicted from the
* connection pool.
*/
private long idleTimeout = 30 * 60 * 1000L;

public int getConnectTimeout() {
return connectTimeout;
}
Expand All @@ -76,14 +69,6 @@ public void setSocketTimeout(int socketTimeout) {
this.socketTimeout = socketTimeout;
}

public long getIdleTimeout() {
return idleTimeout;
}

public void setIdleTimeout(long idleTimeout) {
this.idleTimeout = idleTimeout;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -96,18 +81,18 @@ public boolean equals(Object o) {
RestTemplateTimeoutProperties that = (RestTemplateTimeoutProperties) o;

return connectTimeout == that.connectTimeout && connectRequestTimeout == that.connectRequestTimeout
&& socketTimeout == that.socketTimeout && idleTimeout == that.idleTimeout;
&& socketTimeout == that.socketTimeout;
}

@Override
public int hashCode() {
return Objects.hash(connectTimeout, connectRequestTimeout, socketTimeout, idleTimeout);
return Objects.hash(connectTimeout, connectRequestTimeout, socketTimeout);
}

@Override
public String toString() {
return "RestTemplateTimeoutProperties{" + ", connectTimeout=" + connectTimeout + ", connectRequestTimeout="
+ connectRequestTimeout + ", socketTimeout=" + socketTimeout + ", idleTimeout=" + idleTimeout + '}';
+ connectRequestTimeout + ", socketTimeout=" + socketTimeout + '}';
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 the original author or authors.
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@
package org.springframework.cloud.netflix.eureka.http;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
Expand All @@ -30,10 +29,8 @@
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.cloud.netflix.eureka.RestTemplateTimeoutProperties;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
Expand All @@ -46,13 +43,9 @@
* @author Marcin Grzejszczak
* @author Olga Maciaszek-Sharma
* @author Jiwon Jeon
* @author Armin Krezovic
* @since 3.0.0
*/
public class DefaultEurekaClientHttpRequestFactorySupplier
implements EurekaClientHttpRequestFactorySupplier, DisposableBean {

private final AtomicReference<CloseableHttpClient> ref = new AtomicReference<>();
public class DefaultEurekaClientHttpRequestFactorySupplier implements EurekaClientHttpRequestFactorySupplier {

private final RestTemplateTimeoutProperties restTemplateTimeoutProperties;

Expand All @@ -71,18 +64,7 @@ public DefaultEurekaClientHttpRequestFactorySupplier(RestTemplateTimeoutProperti

@Override
public ClientHttpRequestFactory get(SSLContext sslContext, @Nullable HostnameVerifier hostnameVerifier) {
TimeValue timeValue;

if (restTemplateTimeoutProperties != null) {
timeValue = TimeValue.ofMilliseconds(restTemplateTimeoutProperties.getIdleTimeout());
}
else {
timeValue = TimeValue.of(30, TimeUnit.SECONDS);
}

HttpClientBuilder httpClientBuilder = HttpClients.custom().evictExpiredConnections()
.evictIdleConnections(timeValue);

HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
if (sslContext != null || hostnameVerifier != null || restTemplateTimeoutProperties != null) {
httpClientBuilder.setConnectionManager(
buildConnectionManager(sslContext, hostnameVerifier, restTemplateTimeoutProperties));
Expand All @@ -91,11 +73,7 @@ public ClientHttpRequestFactory get(SSLContext sslContext, @Nullable HostnameVer
httpClientBuilder.setDefaultRequestConfig(buildRequestConfig());
}

if (ref.get() == null) {
ref.compareAndSet(null, httpClientBuilder.build());
}

CloseableHttpClient httpClient = ref.get();
CloseableHttpClient httpClient = httpClientBuilder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
return requestFactory;
Expand Down Expand Up @@ -130,13 +108,4 @@ private RequestConfig buildRequestConfig() {
.build();
}

@Override
public void destroy() throws Exception {
CloseableHttpClient httpClient = ref.get();

if (httpClient != null) {
httpClient.close();
}
}

}

0 comments on commit de2ea96

Please sign in to comment.