Added documentation, changed property name from serviceIds to clienNames, clients

This commit is contained in:
Biju Kunjummen
2017-03-14 04:35:52 -05:00
parent 2d9604918a
commit 427770a6d0
5 changed files with 42 additions and 13 deletions

View File

@@ -863,6 +863,21 @@ public class MyClass {
}
----
[[ribbon-child-context-eager-load]]
=== Caching of Ribbon Configuration
Each Ribbon named client has a corresponding child Application Context that Spring Cloud maintains, this application context is lazily loaded up on the first request to the named client.
This lazy loading behavior can be changed to instead eagerly load up these child Application contexts at startup by specifying the names of the Ribbon clients.
.application.yml
----
ribbon:
eager-load:
enabled: true
clients: client1, client2, client3
----
[[spring-cloud-feign]]
== Declarative REST Client: Feign
@@ -2040,6 +2055,18 @@ public class AddResponseHeaderFilter extends ZuulFilter {
If an exception is thrown during any portion of the Zuul filter lifecycle, the error filters are executed. The `SendErrorFilter` is only run if `RequestContext.getThrowable()` is not `null`. It then sets specific `javax.servlet.error.*` attributes in the request and forwards the request to the Spring Boot error page.
==== Zuul Eager Application Context Loading
Zuul internally uses Ribbon for calling the remote url's and Ribbon clients are by default lazily loaded up by Spring Cloud on first call.
This behavior can be changed for Zuul using the following configuration and will result in the child Ribbon related Application contexts being eagerly loaded up at application startup time.
.application.yml
----
zuul:
ribbon:
eager-load:
enabled: true
----
== Polyglot support with Sidecar

View File

@@ -31,18 +31,20 @@ public class RibbonApplicationContextInitializer
implements ApplicationListener<ApplicationReadyEvent> {
private final SpringClientFactory springClientFactory;
private final List<String> serviceIds;
//List of Ribbon client names
private final List<String> clientNames;
public RibbonApplicationContextInitializer(SpringClientFactory springClientFactory,
List<String> serviceIds) {
List<String> clientNames) {
this.springClientFactory = springClientFactory;
this.serviceIds = serviceIds;
this.clientNames = clientNames;
}
private void initialize() {
if (serviceIds != null) {
for (String serviceId : serviceIds) {
this.springClientFactory.getContext(serviceId);
if (clientNames != null) {
for (String clientName : clientNames) {
this.springClientFactory.getContext(clientName);
}
}
}

View File

@@ -110,7 +110,7 @@ public class RibbonAutoConfiguration {
@ConditionalOnProperty(value = "ribbon.eager-load.enabled", matchIfMissing = false)
public RibbonApplicationContextInitializer ribbonApplicationContextInitializer() {
return new RibbonApplicationContextInitializer(springClientFactory(),
ribbonEagerLoadProperties.getServiceIds());
ribbonEagerLoadProperties.getClients());
}
@Configuration

View File

@@ -29,7 +29,7 @@ import java.util.List;
@ConfigurationProperties(prefix = "ribbon.eager-load")
public class RibbonEagerLoadProperties {
private boolean enabled = false;
private List<String> serviceIds;
private List<String> clients;
public boolean isEnabled() {
return enabled;
@@ -39,11 +39,11 @@ public class RibbonEagerLoadProperties {
this.enabled = enabled;
}
public List<String> getServiceIds() {
return serviceIds;
public List<String> getClients() {
return clients;
}
public void setServiceIds(List<String> serviceIds) {
this.serviceIds = serviceIds;
public void setClients(List<String> clients) {
this.clients = clients;
}
}

View File

@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {
"ribbon.eager-load.enabled=true",
"ribbon.eager-load.serviceIds=testspec1,testspec2"
"ribbon.eager-load.clients=testspec1,testspec2"
})
@DirtiesContext
public class RibbonClientsEagerInitializationTest {