Added documentation, changed property name from serviceIds to clienNames, clients
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user