Merge branch 'aftersss-2.0.x.fix' into 2.0.x

This commit is contained in:
Ryan Baxter
2019-05-21 12:45:21 -04:00
4 changed files with 49 additions and 2 deletions

View File

@@ -324,6 +324,13 @@ eureka.instance.metadataMap.zone = zone2
eureka.client.preferSameZoneEureka = true
```
=== Refreshing Eureka Clients
By default, the `EurekaClient` bean is refreshable, meaning the Eureka client properties can be changed and refreshed.
When a refresh occurs clients will be unregistered from the Eureka server and there might be a brief moment of time
where all instance of a given service are not available. One way to eliminate this from happening is to disable
the ability to refresh Eureka clients. To do this set `eureka.client.refresh.enable=false`.
[[spring-cloud-eureka-server]]
== Service Discovery: Eureka Server

View File

@@ -259,6 +259,7 @@ public class EurekaClientAutoConfiguration {
@Documented
@ConditionalOnClass(RefreshScope.class)
@ConditionalOnBean(RefreshAutoConfiguration.class)
@ConditionalOnProperty(value = "eureka.client.refresh.enable", havingValue = "true", matchIfMissing = true)
@interface ConditionalOnRefreshScope {
}
@@ -376,6 +377,10 @@ public class EurekaClientAutoConfiguration {
static class MissingScope {
}
@ConditionalOnProperty(value = "eureka.client.refresh.enable", havingValue = "false")
static class OnPropertyDisabled {
}
}
@Configuration

View File

@@ -6,6 +6,12 @@
"description": "Enables the Eureka health check handler.",
"type": "java.lang.Boolean"
},
{
"defaultValue": true,
"name": "eureka.client.refresh.enable",
"description": "Determines whether the EurekaClient instance can be refreshed or not(If disabled none of the Eureka client properties will be refreshable).",
"type": "java.lang.Boolean"
},
{
"defaultValue": true,
"name": "ribbon.eureka.enabled",
@@ -13,4 +19,4 @@
"type": "java.lang.Boolean"
}
]
}
}

View File

@@ -20,6 +20,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration.ConditionalOnMissingRefreshScope;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration.ConditionalOnRefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -40,6 +41,20 @@ public class ConditionalOnRefreshScopeTests {
assertThat(c).hasSingleBean(
org.springframework.cloud.context.scope.refresh.RefreshScope.class);
assertThat(c.getBean("foo")).isEqualTo("foo");
assertThat(c).doesNotHaveBean("bar");
});
}
@Test
public void refreshScopeIncludedAndPropertyDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
.withPropertyValues("eureka.client.refresh.enable=false")
.withUserConfiguration(Beans.class).run(c -> {
assertThat(c).hasSingleBean(
org.springframework.cloud.context.scope.refresh.RefreshScope.class);
assertThat(c).doesNotHaveBean("foo");
assertThat(c.getBean("bar")).isEqualTo("bar");
});
}
@@ -47,6 +62,14 @@ public class ConditionalOnRefreshScopeTests {
public void refreshScopeNotIncluded() {
new ApplicationContextRunner().withUserConfiguration(Beans.class).run(c -> {
assertThat(c).doesNotHaveBean("foo");
assertThat(c.getBean("bar")).isEqualTo("bar");
});
new ApplicationContextRunner().withUserConfiguration(Beans.class)
.withPropertyValues("eureka.client.refresh.enable=false")
.run(c -> {
assertThat(c).doesNotHaveBean("foo");
assertThat(c.getBean("bar")).isEqualTo("bar");
});
}
@@ -57,6 +80,12 @@ public class ConditionalOnRefreshScopeTests {
public String foo() {
return "foo";
}
@Bean
@ConditionalOnMissingRefreshScope
public String bar() {
return "bar";
}
}
}
}