Compare commits

..
Author SHA1 Message Date
buildmaster c7885631ed Update SNAPSHOT to 4.1.1 2024-03-27 13:55:43 +00:00
buildmaster bb15b7f40e Bumping versions 2024-03-27 11:05:01 +00:00
Olga MaciaszekSharma c97bd250af Revert "Add support for configuring RestTemplate via RestTemplateBuilder (#4255) (#4262)"
This reverts commit 6b6173de3a.
2024-03-26 19:21:46 +01:00
Olga MaciaszekSharma 4b101efe19 Revert "Update javadocs and license comments for recent changes."
This reverts commit 61d5f5f9fb.
2024-03-26 19:20:44 +01:00
Olga MaciaszekSharma 61d5f5f9fb Update javadocs and license comments for recent changes. 2024-03-26 18:45:31 +01:00
ZIRAKrezovic 6b6173de3a Add support for configuring RestTemplate via RestTemplateBuilder (#4255) (#4262) 2024-03-26 18:42:50 +01:00
ZIRAKrezovic 4536954aca Clean up eureka-client deprecations (#4261) 2024-03-26 17:06:55 +01:00
dependabot[bot] 817ea2c88a Bump testcontainers.version from 1.19.6 to 1.19.7 (#4271) 2024-03-26 15:30:22 +01:00
ZIRAKrezovic 1754585fc0 Enable Connection Evictor in HttpClient (#4103) (#4258) 2024-03-26 15:29:18 +01:00
dependabot[bot] 0bebfd1e3d Bump testcontainers.version from 1.19.4 to 1.19.6 (#4264) 2024-03-25 16:41:34 +01:00
dependabot[bot] a0c95db99e Bump org.glassfish.hk2:spring-bridge from 3.0.6 to 3.1.0 (#4265) 2024-03-25 16:40:43 +01:00
Olga MaciaszekSharma ad002b4da2 Upgrade antora-ui-spring to 0.4.11. 2024-03-07 17:47:04 +01:00
buildmaster fb088832db Bumping versions 2024-03-05 11:04:58 +00:00
buildmaster 3d30846108 Bumping versions 2024-02-23 11:05:23 +00:00
RobertBleyl 3c84f2ec04 Introduce asyncClientInitialization property. (#4239) 2024-02-22 12:48:52 +01:00
Olga MaciaszekSharma 479f10e379 Merge remote-tracking branch 'origin/main' 2024-02-15 18:40:55 +01:00
Olga MaciaszekSharma 1bc989c5ce Remove unnecessary dependency. 2024-02-15 18:40:45 +01:00
dependabot[bot] cf81e327ad Bump testcontainers.version from 1.19.3 to 1.19.4 (#4243)
Bumps `testcontainers.version` from 1.19.3 to 1.19.4.

Updates `org.testcontainers:mockserver` from 1.19.3 to 1.19.4
- [Release notes](https://github.com/testcontainers/testcontainers-java/releases)
- [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.19.3...1.19.4)

Updates `org.testcontainers:junit-jupiter` from 1.19.3 to 1.19.4
- [Release notes](https://github.com/testcontainers/testcontainers-java/releases)
- [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.19.3...1.19.4)

---
updated-dependencies:
- dependency-name: org.testcontainers:mockserver
  dependency-type: direct:development
  update-type: version-update:semver-patch
- dependency-name: org.testcontainers:junit-jupiter
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-14 18:22:43 +01:00
dependabot[bot] 35ef348fe9 Bump org.glassfish.hk2:spring-bridge from 3.0.5 to 3.0.6 (#4245)
Bumps [org.glassfish.hk2:spring-bridge](https://github.com/eclipse-ee4j/glassfish-hk2) from 3.0.5 to 3.0.6.
- [Release notes](https://github.com/eclipse-ee4j/glassfish-hk2/releases)
- [Changelog](https://github.com/eclipse-ee4j/glassfish-hk2/blob/master/CHANGELOG)
- [Commits](https://github.com/eclipse-ee4j/glassfish-hk2/commits)

---
updated-dependencies:
- dependency-name: org.glassfish.hk2:spring-bridge
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-14 18:21:05 +01:00
dependabot[bot] 45ddfdfb7c Bump codecov/codecov-action from 3 to 4 (#4249)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-14 18:20:30 +01:00
Olga MaciaszekSharma 8ae4950200 Upgrade Eureka Server to 2.0.2. Upgrade glassfish spring-bridge to 3.0.6. Fixes gh-4238. 2024-02-14 12:32:53 +01:00
buildmaster d7275b888b Bumping versions 2024-01-31 11:04:43 +00:00
Olga Maciaszek-Sharma ed9ca444c8 Improve documentation on HTTP clients used by EurekaClient. (#4242) 2024-01-25 16:26:18 +01:00
22 changed files with 243 additions and 60 deletions
+1 -1
View File
@@ -28,6 +28,6 @@ jobs:
cache: 'maven'
- name: Build with Maven
run: ./mvnw clean install -B -U -P sonar
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
+1 -1
View File
@@ -36,4 +36,4 @@ runtime:
format: pretty
ui:
bundle:
url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.4.2/ui-bundle.zip
url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.4.11/ui-bundle.zip
@@ -110,6 +110,17 @@ 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.
+3 -1
View File
@@ -47,6 +47,7 @@
|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.
@@ -68,6 +69,7 @@
|eureka.instance.a-s-g-name | | Gets the AWS autoscaling group name associated with this instance. This information is specifically used in an AWS environment to automatically put an instance out of service after the instance is launched and it has been disabled for traffic..
|eureka.instance.app-group-name | | Get the name of the application group to be registered with eureka.
|eureka.instance.appname | `+++unknown+++` | Get the name of the application to be registered with eureka.
|eureka.instance.async-client-initialization | `+++false+++` | If true the EurekaClient will be initialized asynchronously when the InstanceRegistry bean is created.
|eureka.instance.data-center-info | | Returns the data center this instance is deployed. This information is used to get some AWS specific instance information if the instance is deployed in AWS.
|eureka.instance.default-address-resolution-order | `+++[]+++` |
|eureka.instance.environment | |
@@ -173,7 +175,7 @@
|eureka.server.use-read-only-response-cache | `+++true+++` |
|eureka.server.wait-time-in-ms-when-sync-empty | `+++0+++` |
|eureka.server.xml-codec-name | |
|spring.cloud.compatibility-verifier.compatible-boot-versions | `+++3.2.x+++` | Default accepted versions for the Spring Boot dependency. You can set {@code x} for the patch version if you don't want to specify a concrete value. Example: {@code 3.4.x}
|spring.cloud.compatibility-verifier.compatible-boot-versions | | Default accepted versions for the Spring Boot dependency. You can set {@code x} for the patch version if you don't want to specify a concrete value. Example: {@code 3.4.x}
|spring.cloud.compatibility-verifier.enabled | `+++false+++` | Enables creation of Spring Cloud compatibility verification.
|spring.cloud.config.allow-override | `+++true+++` | Flag to indicate that {@link #isOverrideSystemProperties() systemPropertiesOverride} can be used. Set to false to prevent users from changing the default accidentally. Default true.
|spring.cloud.config.initialize-on-context-refresh | `+++false+++` | Flag to initialize bootstrap configuration on context refresh event. Default false.
+1 -1
View File
@@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
<relativePath>..</relativePath>
</parent>
<packaging>jar</packaging>
+5 -5
View File
@@ -3,14 +3,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-netflix</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
<packaging>pom</packaging>
<name>Spring Cloud Netflix</name>
<description>Spring Cloud Netflix</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
<relativePath />
</parent>
<scm>
@@ -21,9 +21,9 @@
</scm>
<properties>
<bintray.package>netflix</bintray.package>
<spring-cloud-commons.version>4.1.1-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-config.version>4.1.1-SNAPSHOT</spring-cloud-config.version>
<testcontainers.version>1.19.3</testcontainers.version>
<spring-cloud-commons.version>4.1.2</spring-cloud-commons.version>
<spring-cloud-config.version>4.1.1</spring-cloud-config.version>
<testcontainers.version>1.19.7</testcontainers.version>
<mockserverclient.version>5.15.0</mockserverclient.version>
<!-- Sonar -->
+3 -3
View File
@@ -5,16 +5,16 @@
<parent>
<artifactId>spring-cloud-dependencies-parent</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
<relativePath/>
</parent>
<artifactId>spring-cloud-netflix-dependencies</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
<packaging>pom</packaging>
<name>spring-cloud-netflix-dependencies</name>
<description>Spring Cloud Netflix Dependencies</description>
<properties>
<eureka.version>2.0.1</eureka.version>
<eureka.version>2.0.2</eureka.version>
</properties>
<dependencyManagement>
<dependencies>
@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
<relativePath>..</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>spring-cloud-netflix-eureka-client-tls-tests</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
<relativePath>..</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2023 the original author or authors.
* Copyright 2013-2024 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.
@@ -103,6 +103,7 @@ import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceI
* @author Daniel Lavoie
* @author Olga Maciaszek-Sharma
* @author Tim Ysewyn
* @author Robert Bleyl
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@@ -224,8 +225,8 @@ public class EurekaClientAutoConfiguration {
}
@Bean
public EurekaServiceRegistry eurekaServiceRegistry() {
return new EurekaServiceRegistry();
public EurekaServiceRegistry eurekaServiceRegistry(EurekaInstanceConfigBean eurekaInstanceConfigBean) {
return new EurekaServiceRegistry(eurekaInstanceConfigBean);
}
// @Bean
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 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.
@@ -38,6 +38,7 @@ import org.springframework.util.StringUtils;
* @author Spencer Gibb
* @author Ryan Baxter
* @author Gregor Zurowski
* @author Robert Bleyl
*/
@ConfigurationProperties("eureka.instance")
public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, EnvironmentAware {
@@ -269,6 +270,12 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, Envi
*/
private boolean preferIpAddress = false;
/**
* If true the EurekaClient will be initialized asynchronously when the
* InstanceRegistry bean is created.
*/
private boolean asyncClientInitialization;
/**
* Initial status to register with remote Eureka server.
*/
@@ -547,6 +554,14 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, Envi
this.preferIpAddress = preferIpAddress;
}
public boolean isAsyncClientInitialization() {
return asyncClientInitialization;
}
public void setAsyncClientInitialization(boolean asyncClientInitialization) {
this.asyncClientInitialization = asyncClientInitialization;
}
public InstanceStatus getInitialStatus() {
return initialStatus;
}
@@ -597,6 +612,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, Envi
&& Objects.equals(namespace, that.namespace) && Objects.equals(hostname, that.hostname)
&& preferIpAddress == that.preferIpAddress && Objects.equals(initialStatus, that.initialStatus)
&& Arrays.equals(defaultAddressResolutionOrder, that.defaultAddressResolutionOrder)
&& asyncClientInitialization == that.asyncClientInitialization
&& Objects.equals(environment, that.environment);
}
@@ -607,7 +623,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, Envi
leaseExpirationDurationInSeconds, virtualHostName, instanceId, secureVirtualHostName, aSGName,
metadataMap, dataCenterInfo, ipAddress, statusPageUrlPath, statusPageUrl, homePageUrlPath, homePageUrl,
healthCheckUrlPath, healthCheckUrl, secureHealthCheckUrl, namespace, hostname, preferIpAddress,
initialStatus, Arrays.hashCode(defaultAddressResolutionOrder), environment);
asyncClientInitialization, initialStatus, Arrays.hashCode(defaultAddressResolutionOrder), environment);
}
@Override
@@ -631,6 +647,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, Envi
.append("', ").append("healthCheckUrl='").append(healthCheckUrl).append("', ")
.append("secureHealthCheckUrl='").append(secureHealthCheckUrl).append("', ").append("namespace='")
.append(namespace).append("', ").append("hostname='").append(hostname).append("', ")
.append("asyncClientInitialization=").append(asyncClientInitialization).append(", ")
.append("preferIpAddress=").append(preferIpAddress).append(", ").append("initialStatus=")
.append(initialStatus).append(", ").append("defaultAddressResolutionOrder=")
.append(Arrays.toString(defaultAddressResolutionOrder)).append(", ").append("environment=")
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 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.
@@ -30,6 +30,7 @@ import org.springframework.web.client.RestTemplate;
* {@link RestTemplateEurekaHttpClient}.
*
* @author Jiwon Jeon
* @author Armin Krezovic
* @since 3.1.6
*/
@ConfigurationProperties("eureka.client.rest-template-timeout")
@@ -45,6 +46,12 @@ 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;
}
@@ -69,6 +76,14 @@ public class RestTemplateTimeoutProperties {
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) {
@@ -81,18 +96,18 @@ public class RestTemplateTimeoutProperties {
RestTemplateTimeoutProperties that = (RestTemplateTimeoutProperties) o;
return connectTimeout == that.connectTimeout && connectRequestTimeout == that.connectRequestTimeout
&& socketTimeout == that.socketTimeout;
&& socketTimeout == that.socketTimeout && idleTimeout == that.idleTimeout;
}
@Override
public int hashCode() {
return Objects.hash(connectTimeout, connectRequestTimeout, socketTimeout);
return Objects.hash(connectTimeout, connectRequestTimeout, socketTimeout, idleTimeout);
}
@Override
public String toString() {
return "RestTemplateTimeoutProperties{" + ", connectTimeout=" + connectTimeout + ", connectRequestTimeout="
+ connectRequestTimeout + ", socketTimeout=" + socketTimeout + '}';
+ connectRequestTimeout + ", socketTimeout=" + socketTimeout + ", idleTimeout=" + idleTimeout + '}';
}
}
@@ -33,6 +33,7 @@ import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
import org.springframework.cloud.configuration.TlsProperties;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.cloud.netflix.eureka.RestTemplateTimeoutProperties;
import org.springframework.cloud.netflix.eureka.http.DefaultEurekaClientHttpRequestFactorySupplier;
import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFactorySupplier;
import org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient;
@@ -55,7 +56,7 @@ import org.springframework.web.reactive.function.client.WebClient;
@ConditionalOnClass(ConfigServicePropertySourceLocator.class)
@Conditional(EurekaConfigServerBootstrapConfiguration.EurekaConfigServerBootstrapCondition.class)
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@EnableConfigurationProperties(RestTemplateTimeoutProperties.class)
public class EurekaConfigServerBootstrapConfiguration {
@Bean
@@ -78,8 +79,9 @@ public class EurekaConfigServerBootstrapConfiguration {
@Bean
@ConditionalOnMissingBean
EurekaClientHttpRequestFactorySupplier defaultEurekaClientHttpRequestFactorySupplier() {
return new DefaultEurekaClientHttpRequestFactorySupplier();
EurekaClientHttpRequestFactorySupplier defaultEurekaClientHttpRequestFactorySupplier(
RestTemplateTimeoutProperties restTemplateTimeoutProperties) {
return new DefaultEurekaClientHttpRequestFactorySupplier(restTemplateTimeoutProperties);
}
@Bean
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 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.
@@ -17,6 +17,7 @@
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;
@@ -29,8 +30,10 @@ import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuil
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;
@@ -43,9 +46,13 @@ import org.springframework.lang.Nullable;
* @author Marcin Grzejszczak
* @author Olga Maciaszek-Sharma
* @author Jiwon Jeon
* @author Armin Krezovic
* @since 3.0.0
*/
public class DefaultEurekaClientHttpRequestFactorySupplier implements EurekaClientHttpRequestFactorySupplier {
public class DefaultEurekaClientHttpRequestFactorySupplier
implements EurekaClientHttpRequestFactorySupplier, DisposableBean {
private final AtomicReference<CloseableHttpClient> ref = new AtomicReference<>();
private final RestTemplateTimeoutProperties restTemplateTimeoutProperties;
@@ -64,7 +71,18 @@ public class DefaultEurekaClientHttpRequestFactorySupplier implements EurekaClie
@Override
public ClientHttpRequestFactory get(SSLContext sslContext, @Nullable HostnameVerifier hostnameVerifier) {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
TimeValue timeValue;
if (restTemplateTimeoutProperties != null) {
timeValue = TimeValue.ofMilliseconds(restTemplateTimeoutProperties.getIdleTimeout());
}
else {
timeValue = TimeValue.of(30, TimeUnit.SECONDS);
}
HttpClientBuilder httpClientBuilder = HttpClients.custom().evictExpiredConnections()
.evictIdleConnections(timeValue);
if (sslContext != null || hostnameVerifier != null || restTemplateTimeoutProperties != null) {
httpClientBuilder.setConnectionManager(
buildConnectionManager(sslContext, hostnameVerifier, restTemplateTimeoutProperties));
@@ -73,7 +91,11 @@ public class DefaultEurekaClientHttpRequestFactorySupplier implements EurekaClie
httpClientBuilder.setDefaultRequestConfig(buildRequestConfig());
}
CloseableHttpClient httpClient = httpClientBuilder.build();
if (ref.get() == null) {
ref.compareAndSet(null, httpClientBuilder.build());
}
CloseableHttpClient httpClient = ref.get();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
return requestFactory;
@@ -108,4 +130,13 @@ public class DefaultEurekaClientHttpRequestFactorySupplier implements EurekaClie
.build();
}
@Override
public void destroy() throws Exception {
CloseableHttpClient httpClient = ref.get();
if (httpClient != null) {
httpClient.close();
}
}
}
@@ -209,11 +209,6 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
return response.getStatusCode();
}
@Override
public int getRawStatusCode() throws IOException {
return response.getRawStatusCode();
}
@Override
public String getStatusText() throws IOException {
return response.getStatusText();
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 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.
@@ -17,25 +17,54 @@
package org.springframework.cloud.netflix.eureka.serviceregistry;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.netflix.appinfo.InstanceInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import static com.netflix.appinfo.InstanceInfo.InstanceStatus.UNKNOWN;
/**
* @author Spencer Gibb
* @author Robert Bleyl
*/
public class EurekaServiceRegistry implements ServiceRegistry<EurekaRegistration> {
private static final Log log = LogFactory.getLog(EurekaServiceRegistry.class);
private EurekaInstanceConfigBean eurekaInstanceConfigBean;
public EurekaServiceRegistry() {
}
public EurekaServiceRegistry(EurekaInstanceConfigBean eurekaInstanceConfigBean) {
this.eurekaInstanceConfigBean = eurekaInstanceConfigBean;
}
@Override
public void register(EurekaRegistration reg) {
maybeInitializeClient(reg);
if (eurekaInstanceConfigBean != null && eurekaInstanceConfigBean.isAsyncClientInitialization()) {
if (log.isDebugEnabled()) {
log.debug("Initializing client asynchronously...");
}
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> {
maybeInitializeClient(reg);
if (log.isDebugEnabled()) {
log.debug("Asynchronous client initialization done.");
}
});
}
else {
maybeInitializeClient(reg);
}
if (log.isInfoEnabled()) {
log.info("Registering application " + reg.getApplicationInfoManager().getInfo().getAppName()
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 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.
@@ -26,11 +26,12 @@ import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.netflix.eureka.http.WebClientEurekaHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import static org.assertj.core.api.Assertions.assertThat;
@@ -53,10 +54,12 @@ class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
@Test
void webClientRespectsCodecProperties() {
WebClient webClient = eurekaHttpClient.getWebClient();
ClientResponse response = webClient.get().uri("http://localhost:" + port).exchange().block();
ResponseEntity<String> response = webClient.get().uri("http://localhost:" + port).retrieve()
.toEntity(String.class).block();
assertThat(response).isNotNull();
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.bodyToMono(String.class).block()).startsWith("....").hasSize(300000);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).startsWith("....").hasSize(300000);
}
@SpringBootConfiguration
@@ -71,8 +74,8 @@ class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests().anyRequest().permitAll().and().csrf().disable();
return http.build();
return http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.csrf(AbstractHttpConfigurer::disable).build();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 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.
@@ -16,14 +16,20 @@
package org.springframework.cloud.netflix.eureka.serviceregistry;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.InstanceInfo;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.commons.util.InetUtilsProperties;
import org.springframework.cloud.loadbalancer.support.SimpleObjectProvider;
import org.springframework.cloud.netflix.eureka.CloudEurekaClient;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
@@ -33,16 +39,24 @@ import static com.netflix.appinfo.InstanceInfo.InstanceStatus.DOWN;
import static com.netflix.appinfo.InstanceInfo.InstanceStatus.OUT_OF_SERVICE;
import static com.netflix.appinfo.InstanceInfo.InstanceStatus.UNKNOWN;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
/**
* @author Spencer Gibb
* @author Tim Ysewyn
* @author Robert Bleyl
*/
@ExtendWith(MockitoExtension.class)
class EurekaServiceRegistryTests {
@Mock
private EurekaInstanceConfigBean eurekaInstanceConfigBean;
@Test
void eurekaClientNotShutdownInDeregister() {
EurekaServiceRegistry registry = new EurekaServiceRegistry();
@@ -110,8 +124,6 @@ class EurekaServiceRegistryTests {
CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
when(eurekaClient.getInstanceInfo("myapp", "1234")).thenReturn(null);
ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));
@@ -130,4 +142,54 @@ class EurekaServiceRegistryTests {
assertThat(map).hasSize(1).containsEntry("status", UNKNOWN.toString());
}
@Test
void eurekaClientInitializesClientAsynchronously() {
when(eurekaInstanceConfigBean.isAsyncClientInitialization()).thenReturn(true);
EurekaServiceRegistry registry = new EurekaServiceRegistry(eurekaInstanceConfigBean);
final AtomicBoolean applicationsFetched = new AtomicBoolean();
CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
when(eurekaClient.getApplications()).thenAnswer((answer) -> {
applicationsFetched.set(true);
return answer;
});
ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));
EurekaRegistration registration = EurekaRegistration
.builder(new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()))).with(eurekaClient)
.with(applicationInfoManager).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
.with(new SimpleObjectProvider<>(null)).build();
registry.register(registration);
await().atMost(Duration.ofSeconds(5)).pollInterval(Duration.ofMillis(500)).until(applicationsFetched::get);
verify(eurekaClient).getApplications();
assertThat(applicationsFetched).isTrue();
}
@Test
void eurekaClientInitializesClientSynchronously() {
EurekaServiceRegistry registry = new EurekaServiceRegistry(eurekaInstanceConfigBean);
CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));
EurekaRegistration registration = EurekaRegistration
.builder(new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()))).with(eurekaClient)
.with(applicationInfoManager).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
.with(new SimpleObjectProvider<>(null)).build();
registry.register(registration);
verify(eurekaClient).getApplications();
verify(eurekaClient, never()).getEurekaClientConfig();
}
}
+2 -8
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
<relativePath>..</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
@@ -76,13 +76,7 @@
<groupId>org.glassfish.hk2</groupId>
<artifactId>spring-bridge</artifactId>
<!-- FIXME: 4.0 -->
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<!-- FIXME: 4.0 -->
<version>2.0.1</version>
<version>3.1.0</version>
</dependency>
<!-- Eureka deps that are now optional in eureka -->
<dependency>
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 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.
@@ -25,6 +25,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Pattern;
import com.netflix.appinfo.ApplicationInfoManager;
@@ -88,6 +90,7 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.actuator.HasFeatures;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.netflix.eureka.EurekaConstants;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
@@ -108,6 +111,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @author Biju Kunjummen
* @author Fahim Farook
* @author Weix Sun
* @author Robert Bleyl
*/
@Configuration(proxyBeanMethods = false)
@Import(EurekaServerInitializerConfiguration.class)
@@ -207,8 +211,25 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
@Bean
public PeerAwareInstanceRegistry peerAwareInstanceRegistry(ServerCodecs serverCodecs,
EurekaServerHttpClientFactory eurekaServerHttpClientFactory) {
this.eurekaClient.getApplications(); // force initialization
EurekaServerHttpClientFactory eurekaServerHttpClientFactory,
EurekaInstanceConfigBean eurekaInstanceConfigBean) {
if (eurekaInstanceConfigBean.isAsyncClientInitialization()) {
if (log.isDebugEnabled()) {
log.debug("Initializing client asynchronously...");
}
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> {
this.eurekaClient.getApplications();
if (log.isDebugEnabled()) {
log.debug("Asynchronous client initialization done.");
}
});
}
else {
this.eurekaClient.getApplications(); // force initialization
}
return new InstanceRegistry(this.eurekaServerConfig, this.eurekaClientConfig, serverCodecs, this.eurekaClient,
eurekaServerHttpClientFactory,
this.instanceRegistryProperties.getExpectedNumberOfClientsSendingRenews(),
@@ -4,7 +4,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
</parent>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<name>Spring Cloud Starter Netflix Eureka Client</name>
@@ -3,7 +3,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.1</version>
</parent>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<name>Spring Cloud Starter Netflix Eureka Server</name>