Merge remote-tracking branch 'origin/2.1.x'

This commit is contained in:
Ryan Baxter
2019-05-21 13:00:16 -04:00
5 changed files with 49 additions and 3 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

@@ -382,6 +382,7 @@ public class EurekaClientAutoConfiguration {
@Documented
@ConditionalOnClass(RefreshScope.class)
@ConditionalOnBean(RefreshAutoConfiguration.class)
@ConditionalOnProperty(value = "eureka.client.refresh.enable", havingValue = "true", matchIfMissing = true)
@interface ConditionalOnRefreshScope {
}
@@ -402,6 +403,11 @@ public class EurekaClientAutoConfiguration {
}
@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

@@ -21,6 +21,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;
@@ -44,11 +45,31 @@ public class ConditionalOnRefreshScopeTests {
});
}
@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");
});
}
@Test
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");
});
}
@Configuration
@@ -60,6 +81,12 @@ public class ConditionalOnRefreshScopeTests {
return "foo";
}
@Bean
@ConditionalOnMissingRefreshScope
public String bar() {
return "bar";
}
}
}

View File

@@ -184,8 +184,8 @@ public class SendResponseFilter extends ZuulFilter {
}
}
//cleanup ThreadLocal when we are all done
if(buffers != null) {
// cleanup ThreadLocal when we are all done
if (buffers != null) {
buffers.remove();
}