Added java configuration for the retry.adoc
This commit is contained in:
@@ -244,11 +244,16 @@ configure AOP interceptors, see the Spring User Guide):
|
||||
public MyService myService() {
|
||||
ProxyFactory factory = new ProxyFactory(RepeatOperations.class.getClassLoader());
|
||||
factory.setInterfaces(MyService.class);
|
||||
factory.setTarget(target);
|
||||
service = (Service) factory.getProxy();
|
||||
factory.setTarget(new MyService());
|
||||
|
||||
MyService service = (MyService) factory.getProxy();
|
||||
JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
|
||||
pointcut.setPatterns(".*processMessage.*");
|
||||
((Advised) service).addAdvice(new DefaultPointcutAdvisor(pointcut, interceptor));
|
||||
|
||||
RepeatOperationsInterceptor interceptor = new RepeatOperationsInterceptor();
|
||||
|
||||
((Advised) service).addAdvisor(new DefaultPointcutAdvisor(pointcut, interceptor));
|
||||
|
||||
return service;
|
||||
}
|
||||
----
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
== Retry
|
||||
|
||||
include::toggle.adoc[]
|
||||
|
||||
To make processing more robust and less prone to failure, it sometimes
|
||||
helps to automatically retry a failed operation in case it might
|
||||
succeed on a subsequent attempt. Errors that are susceptible to intermittent failure
|
||||
@@ -399,13 +401,14 @@ Sometimes, there is some business processing that you know you want
|
||||
`RetryPolicy` in the provided
|
||||
`RepeatTemplate`.
|
||||
|
||||
The following example shows a declarative iteration that uses the Spring AOP
|
||||
namespace to repeat a service call to a method called
|
||||
[role="xmlContent"]
|
||||
The following example shows a declarative retry that uses the Spring AOP
|
||||
namespace to retry a service call to a method called
|
||||
`remoteCall` (for more detail on how to configure
|
||||
AOP interceptors, see the Spring User Guide):
|
||||
|
||||
|
||||
[source, xml]
|
||||
[source, xml, role="xmlContent"]
|
||||
----
|
||||
<aop:config>
|
||||
<aop:pointcut id="transactional"
|
||||
@@ -418,6 +421,33 @@ The following example shows a declarative iteration that uses the Spring AOP
|
||||
class="org.springframework.batch.retry.interceptor.RetryOperationsInterceptor"/>
|
||||
----
|
||||
|
||||
[role="javaContent"]
|
||||
The following example shows a declarative retry that uses java configuration
|
||||
to retry a service call to a method called
|
||||
`remoteCall` (for more detail on how to configure
|
||||
AOP interceptors, see the Spring User Guide):
|
||||
|
||||
|
||||
[source, java, role="javaContent"]
|
||||
----
|
||||
@Bean
|
||||
public MyService myService() {
|
||||
ProxyFactory factory = new ProxyFactory(RepeatOperations.class.getClassLoader());
|
||||
factory.setInterfaces(MyService.class);
|
||||
factory.setTarget(new MyService());
|
||||
|
||||
MyService service = (MyService) factory.getProxy();
|
||||
JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
|
||||
pointcut.setPatterns(".*remoteCall.*");
|
||||
|
||||
RetryOperationsInterceptor interceptor = new RetryOperationsInterceptor();
|
||||
|
||||
((Advised) service).addAdvisor(new DefaultPointcutAdvisor(pointcut, interceptor));
|
||||
|
||||
return service;
|
||||
}
|
||||
----
|
||||
|
||||
The preceding example uses a default
|
||||
`RetryTemplate` inside the interceptor. To change the
|
||||
policies or listeners, you can inject an instance of
|
||||
|
||||
Reference in New Issue
Block a user