From fbc4d81cd619e77dbcc24c7f70e52f14950ce48b 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 { diff --git a/1.3.x/single/spring-cloud-commons.html b/1.3.x/single/spring-cloud-commons.html index 96d519aa..0892c77f 100644 --- a/1.3.x/single/spring-cloud-commons.html +++ b/1.3.x/single/spring-cloud-commons.html @@ -245,7 +245,36 @@ you would like to use for a given service.
Note
client
in the above examples should be replaced with your Ribbon client’s -name.If you want a
RestTemplate
that is not load balanced, create aRestTemplate
+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 { diff --git a/1.3.x/spring-cloud-commons.xml b/1.3.x/spring-cloud-commons.xml index 57949433..3a308522 100644 --- a/1.3.x/spring-cloud-commons.xml +++ b/1.3.x/spring-cloud-commons.xml @@ -431,6 +431,37 @@ public class MyConfiguration {+ 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... + } + }}; + } + }; + } +}