From cdf575d006dc9d202f73a026055ee052a7ed2d7e Mon Sep 17 00:00:00 2001
From: buildmaster
Note
client
in the above examples should be replaced with your Ribbon client’s -name.If you want to add one or more
RetryListener
to your retry you will need to +create a bean of typeLoadBalancedRetryListenerFactory
and return theRetryListener
array +you would like to use for a given service.@Configuration +public class MyConfiguration { + @Bean + LoadBalancedRetryListenerFactory retryListenerFactory() { + return new LoadBalancedRetryListenerFactory() { + @Override + public RetryListener[] createRetryListeners(String service) { + return new RetryListener[]{new RetryListener() { + @Override + public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) { + //TODO Do you business... + return true; + } + + @Override + public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) { + //TODO Do you business... + } + + @Override + public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) { + //TODO Do you business... + } + }}; + } + }; + } +}If you want a
RestTemplate
that is not load balanced, create aRestTemplate
bean and inject it as normal. To access the load balancedRestTemplate
use the@LoadBalanced
qualifier when you create your@Bean
.
Important Notice the
@Primary
annotation on the plainRestTemplate
declaration in the example below, to disambiguate the unqualified@Autowired
injection.@Configuration public class MyConfiguration { @@ -110,7 +139,7 @@ the@LoadBalanced
qualifier when you create yourpublic String doStuff() { return restTemplate.getForObject("http://example.com", String.class); } -}
Tip If you see errors like
java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89
try injectingRestOperations
instead or settingspring.aop.proxyTargetClass=true
.
WebClient
can be configured to use theLoadBalancerClient. A `LoadBalancerExchangeFilterFunction
is auto-configured if spring-webflux is on the classpath.public class MyClass { +}
Tip If you see errors like
java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89
try injectingRestOperations
instead or settingspring.aop.proxyTargetClass=true
.
WebClient
can be configured to use theLoadBalancerClient. A `LoadBalancerExchangeFilterFunction
is auto-configured if spring-webflux is on the classpath.public class MyClass { @Autowired private LoadBalancerExchangeFilterFunction lbFunction; @@ -124,7 +153,7 @@ the@LoadBalanced
qualifier when you create yourclass); } } The URI needs to use a virtual host name (ie. service name, not a host name). -The
LoadBalancerClient
is used to create a full physical address.Sometimes it is useful to ignore certain named network interfaces so they can be excluded from Service Discovery registration (eg. running in a Docker container). A list of regular expressions can be set that will cause the desired network interfaces to be ignored. The following configuration will ignore the "docker0" interface and all interfaces that start with "veth".
application.yml. +The
LoadBalancerClient
is used to create a full physical address.Sometimes it is useful to ignore certain named network interfaces so they can be excluded from Service Discovery registration (eg. running in a Docker container). A list of regular expressions can be set that will cause the desired network interfaces to be ignored. The following configuration will ignore the "docker0" interface and all interfaces that start with "veth".
application.yml.
spring: cloud: inetutils: @@ -143,7 +172,7 @@ TheLoadBalancerClient
is used to create a full phy cloud: inetutils: useOnlySiteLocalInterfaces: true-
Spring Cloud Commons provides beans for creating both Apache HTTP clients (
ApacheHttpClientFactory
) +Spring Cloud Commons provides beans for creating both Apache HTTP clients (
-ApacheHttpClientFactory
) as well as OK HTTP clients (OkHttpClientFactory
). TheOkHttpClientFactory
bean will only be created if the OK HTTP jar is on the classpath. In addition, Spring Cloud Commons provides beans for creating the connection managers used by both clients,ApacheHttpClientConnectionManagerFactory
for the Apache diff --git a/multi/multi_spring-cloud-commons.html b/multi/multi_spring-cloud-commons.html index f092de53..a16ad376 100644 --- a/multi/multi_spring-cloud-commons.html +++ b/multi/multi_spring-cloud-commons.html @@ -1,3 +1,3 @@Cloud Native Applications \ No newline at end of file +Table of Contents
- 1. Spring Cloud Context: Application Context Services
- 1.1. The Bootstrap Application Context
- 1.2. Application Context Hierarchies
- 1.3. Changing the Location of Bootstrap Properties
- 1.4. Overriding the Values of Remote Properties
- 1.5. Customizing the Bootstrap Configuration
- 1.6. Customizing the Bootstrap Property Sources
- 1.7. Environment Changes
- 1.8. Refresh Scope
- 1.9. Encryption and Decryption
- 1.10. Endpoints
- 2. Spring Cloud Commons: Common Abstractions
Cloud Native Applications Table of Contents
- 1. Spring Cloud Context: Application Context Services
- 1.1. The Bootstrap Application Context
- 1.2. Application Context Hierarchies
- 1.3. Changing the Location of Bootstrap Properties
- 1.4. Overriding the Values of Remote Properties
- 1.5. Customizing the Bootstrap Configuration
- 1.6. Customizing the Bootstrap Property Sources
- 1.7. Environment Changes
- 1.8. Refresh Scope
- 1.9. Encryption and Decryption
- 1.10. Endpoints
- 2. Spring Cloud Commons: Common Abstractions