From 35e5156bdb8903605c1df6dd2205b07ab6da6689 Mon Sep 17 00:00:00 2001 From: liujiong1982 Date: Mon, 21 Jul 2014 22:15:19 +0800 Subject: [PATCH] INTSAMPLES-133:Use Update the retry-and-more Sample to use Syntax Polishing - add info to README. Also, use "localhost" for amqp connection factories. --- .../spring-integration-context.xml | 2 +- .../spring-integration-context.xml | 2 +- intermediate/retry-and-more/README.md | 6 +++++ .../samples/advice/CircuitBreakerDemo.java | 7 +++++- .../FileTransferDeleteAfterSuccessDemo.java | 2 ++ .../FileTransferRenameAfterFailureDemo.java | 2 ++ .../samples/advice/StatefulRetryDemo.java | 7 +++++- .../samples/advice/StatelessRetryDemo.java | 7 +++++- .../stateful-retry-advice-context.xml | 2 +- .../stateless-retry-advice-context.xml | 25 ++++--------------- 10 files changed, 36 insertions(+), 26 deletions(-) diff --git a/basic/amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml b/basic/amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml index a888f97c..0780ab18 100644 --- a/basic/amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml +++ b/basic/amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml @@ -42,7 +42,7 @@ - + diff --git a/basic/tcp-amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml b/basic/tcp-amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml index bbc13dd2..bc55412f 100644 --- a/basic/tcp-amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml +++ b/basic/tcp-amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml @@ -37,7 +37,7 @@ - + diff --git a/intermediate/retry-and-more/README.md b/intermediate/retry-and-more/README.md index 36ea3925..6e8bf545 100644 --- a/intermediate/retry-and-more/README.md +++ b/intermediate/retry-and-more/README.md @@ -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 ``. 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 `` (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 `` definitions as is shown here. ##Circuit Breaker Advice Demo diff --git a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/CircuitBreakerDemo.java b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/CircuitBreakerDemo.java index 592c19a0..18ca0653 100644 --- a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/CircuitBreakerDemo.java +++ b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/CircuitBreakerDemo.java @@ -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(); } + } diff --git a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/FileTransferDeleteAfterSuccessDemo.java b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/FileTransferDeleteAfterSuccessDemo.java index 5cbb98e5..7ab0df06 100644 --- a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/FileTransferDeleteAfterSuccessDemo.java +++ b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/FileTransferDeleteAfterSuccessDemo.java @@ -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); } } diff --git a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/FileTransferRenameAfterFailureDemo.java b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/FileTransferRenameAfterFailureDemo.java index fbe9006d..eb3c256f 100644 --- a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/FileTransferRenameAfterFailureDemo.java +++ b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/FileTransferRenameAfterFailureDemo.java @@ -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); } } diff --git a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/StatefulRetryDemo.java b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/StatefulRetryDemo.java index 647f20db..d8136e3f 100644 --- a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/StatefulRetryDemo.java +++ b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/StatefulRetryDemo.java @@ -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(); } + } diff --git a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/StatelessRetryDemo.java b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/StatelessRetryDemo.java index c16df9de..5b8df82f 100644 --- a/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/StatelessRetryDemo.java +++ b/intermediate/retry-and-more/src/main/java/org/springframework/integration/samples/advice/StatelessRetryDemo.java @@ -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(); } + } diff --git a/intermediate/retry-and-more/src/main/resources/META-INF/spring/integration/stateful-retry-advice-context.xml b/intermediate/retry-and-more/src/main/resources/META-INF/spring/integration/stateful-retry-advice-context.xml index 36e42577..cc19749b 100644 --- a/intermediate/retry-and-more/src/main/resources/META-INF/spring/integration/stateful-retry-advice-context.xml +++ b/intermediate/retry-and-more/src/main/resources/META-INF/spring/integration/stateful-retry-advice-context.xml @@ -62,7 +62,7 @@ - + diff --git a/intermediate/retry-and-more/src/main/resources/META-INF/spring/integration/stateless-retry-advice-context.xml b/intermediate/retry-and-more/src/main/resources/META-INF/spring/integration/stateless-retry-advice-context.xml index 60db3709..f3b32c99 100644 --- a/intermediate/retry-and-more/src/main/resources/META-INF/spring/integration/stateless-retry-advice-context.xml +++ b/intermediate/retry-and-more/src/main/resources/META-INF/spring/integration/stateless-retry-advice-context.xml @@ -37,36 +37,21 @@ - + - - - - - - - - - - - - + + + - - - - - - - +