Supplement spring-retry listener features (#298)

* Supplement spring-retry listener features
This commit is contained in:
saga
2017-12-22 23:32:39 +08:00
committed by Ryan Baxter
parent fb76beb3f2
commit f54e4c8cc6
5 changed files with 255 additions and 13 deletions

View File

@@ -428,6 +428,42 @@ public class MyConfiguration {
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 type `LoadBalancedRetryListenerFactory` and return the `RetryListener` array
you would like to use for a given service.
[source,java,indent=0]
----
@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...
}
}};
}
};
}
}
----
=== Multiple RestTemplate objects
If you want a `RestTemplate` that is not load balanced, create a `RestTemplate`