INTSAMPLES-133:Use <int:handler-retry-advice/>
Update the retry-and-more Sample to use <int:retry-advice/> Syntax Polishing - add info to README. Also, use "localhost" for amqp connection factories.
This commit is contained in:
committed by
Gary Russell
parent
9eccb86adf
commit
35e5156bdb
@@ -42,7 +42,7 @@
|
||||
|
||||
<!-- Infrastructure -->
|
||||
|
||||
<rabbit:connection-factory id="connectionFactory" />
|
||||
<rabbit:connection-factory id="connectionFactory" host="localhost" />
|
||||
|
||||
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" />
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
<!-- Infrastructure -->
|
||||
|
||||
<rabbit:connection-factory id="connectionFactory" />
|
||||
<rabbit:connection-factory id="connectionFactory" host="localhost" />
|
||||
|
||||
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" />
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ Handler Advice Sample "retry-and-more"
|
||||
|
||||
This sample shows how to use the 2.2.0 Handler Advice feature.
|
||||
|
||||
|
||||
##Stateless Retry Advice Demo
|
||||
|
||||
This class (`StatelessRetryDemo`) demonstrates stateless retry.
|
||||
@@ -18,6 +19,10 @@ In each case enter 'fail n' where n is the number of times you want the service
|
||||
|
||||
e.g. 'fail 2' will succeed in each case on the third try, 'fail 3' will fail permanently after the third try.
|
||||
|
||||
__NOTE: Starting with Spring Integration 4.0, stateless retry has convenient namespace support; this sample has been updated to show its use.__
|
||||
|
||||
It shows the retry advice declared (for each profile) as a top level bean `<int:handler-retry-advice id="retryAdvice">`. Declaring it as a top level bean allows it to be used in multiple places (or via profiles). You can also declare it within the advice chain using `<int:retry-advice/>` (with no 'id'). In that case, it cannot be reused in other advice chains.
|
||||
|
||||
|
||||
##Stateful Retry Advice Demo
|
||||
|
||||
@@ -25,6 +30,7 @@ This class (`StatefulRetryDemo`) demonstrates stateful retry.
|
||||
|
||||
It is similar to the default version of the stateless retry but uses AMQP; you will see that the exception are thrown back to the container and the retries are re-delivered by AMQP.
|
||||
|
||||
NOTE: Starting with Spring Integration 4.0, __stateless retry__ has convenient namespace support; stateful retry requires the retry advice to be configured using `<bean/>` definitions as is shown here.
|
||||
|
||||
##Circuit Breaker Advice Demo
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.samples.advice;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@@ -28,7 +29,7 @@ public class CircuitBreakerDemo {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(CircuitBreakerDemo.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
LOGGER.info("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Welcome to Spring Integration! "
|
||||
@@ -51,8 +52,12 @@ public class CircuitBreakerDemo {
|
||||
+ "\n Service will succeed only in the last quarter "
|
||||
+ "\n minute. Breaker will open after 2 failures and "
|
||||
+ "\n will go half-open after 15 seconds. "
|
||||
+ "\n Demo will terminate in 2 minutes. "
|
||||
+ "\n "
|
||||
+ "\n=========================================================" );
|
||||
|
||||
Thread.sleep(120000);
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
@@ -74,6 +75,7 @@ public class FileTransferDeleteAfterSuccessDemo {
|
||||
+ "\n=========================================================" );
|
||||
|
||||
System.in.read();
|
||||
context.close();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
@@ -70,6 +71,7 @@ public class FileTransferRenameAfterFailureDemo {
|
||||
+ "\n=========================================================" );
|
||||
|
||||
System.in.read();
|
||||
context.close();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.samples.advice;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@@ -28,7 +29,7 @@ public class StatefulRetryDemo {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(StatefulRetryDemo.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
LOGGER.info("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Welcome to Spring Integration! "
|
||||
@@ -50,8 +51,12 @@ public class StatefulRetryDemo {
|
||||
+ "\n Please enter some text and press return. "
|
||||
+ "\n 'fail 2' will fail twice, then succeed "
|
||||
+ "\n 'fail 3' will fail and never succeed "
|
||||
+ "\n Demo will terminate in 60 seconds. "
|
||||
+ "\n "
|
||||
+ "\n=========================================================" );
|
||||
|
||||
Thread.sleep(60000);
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.samples.advice;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@@ -28,7 +29,7 @@ public class StatelessRetryDemo {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(StatelessRetryDemo.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
LOGGER.info("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Welcome to Spring Integration! "
|
||||
@@ -50,8 +51,12 @@ public class StatelessRetryDemo {
|
||||
+ "\n Please enter some text and press return. "
|
||||
+ "\n 'fail 2' will fail twice, then succeed "
|
||||
+ "\n 'fail 3' will fail and never succeed "
|
||||
+ "\n Demo will terminate in 60 seconds. "
|
||||
+ "\n "
|
||||
+ "\n=========================================================" );
|
||||
|
||||
Thread.sleep(60000);
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
|
||||
<!-- Rabbit infrastructure -->
|
||||
|
||||
<rabbit:connection-factory id="connectionFactory" />
|
||||
<rabbit:connection-factory id="connectionFactory" host="localhost" />
|
||||
|
||||
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" />
|
||||
|
||||
|
||||
@@ -37,36 +37,21 @@
|
||||
<!-- Default retry advice 3 tries, no backoff, no recovery;
|
||||
final failure will go to poller's error channel -->
|
||||
<beans profile="default">
|
||||
<bean id="retryAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice" />
|
||||
<int:handler-retry-advice id="retryAdvice" />
|
||||
</beans>
|
||||
|
||||
<!-- Retry advice, template with default 3 tries, exponential backoff, no recovery;
|
||||
final failure will go to poller's error channel -->
|
||||
<beans profile="backoff">
|
||||
<bean id="retryAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
|
||||
<property name="retryTemplate">
|
||||
<bean class="org.springframework.retry.support.RetryTemplate">
|
||||
<property name="backOffPolicy">
|
||||
<bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
|
||||
<property name="initialInterval" value="2000" />
|
||||
<property name="multiplier" value="2" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<int:handler-retry-advice id="retryAdvice">
|
||||
<int:exponential-back-off initial="2000" multiplier="2" />
|
||||
</int:handler-retry-advice>
|
||||
</beans>
|
||||
|
||||
<!-- Retry advice, template with default 3 tries, no backoff, recovery;
|
||||
final handled by recovery instead of going to the poller's error channel -->
|
||||
<beans profile="recovery">
|
||||
<bean id="retryAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
|
||||
<property name="recoveryCallback">
|
||||
<bean class="org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer">
|
||||
<constructor-arg ref="recoveryChannel" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<int:handler-retry-advice id="retryAdvice" recovery-channel="recoveryChannel" />
|
||||
|
||||
<int:channel id="recoveryChannel" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user