Created
September 5, 2014 14:07
-
-
Save golonzovsky/c97cd23f010df48b46d7 to your computer and use it in GitHub Desktop.
retry service activator gateway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.springframework.integration.samples.advice.retry; | |
public interface FileStoreRetryGateway { | |
boolean isExist(String id); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.springframework.integration.samples</groupId> | |
<artifactId>retry-and-more</artifactId> | |
<version>2.2.0.BUILD-SNAPSHOT</version> | |
<name>Retry and More Sample</name> | |
<description>Retry and More Sample</description> | |
<url>http://projects.spring.io/spring-integration</url> | |
<organization> | |
<name>SpringIO</name> | |
<url>https://spring.io</url> | |
</organization> | |
<licenses> | |
<license> | |
<name>The Apache Software License, Version 2.0</name> | |
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | |
<distribution>repo</distribution> | |
</license> | |
</licenses> | |
<developers> | |
<developer> | |
<id>garyrussell</id> | |
<name>Gary Russell</name> | |
<email>[email protected]</email> | |
<roles> | |
<role>project lead</role> | |
</roles> | |
</developer> | |
<developer> | |
<id>markfisher</id> | |
<name>Mark Fisher</name> | |
<email>[email protected]</email> | |
<roles> | |
<role>project founder and lead emeritus</role> | |
</roles> | |
</developer> | |
<developer> | |
<id>ghillert</id> | |
<name>Gunnar Hillert</name> | |
<email>[email protected]</email> | |
</developer> | |
<developer> | |
<id>abilan</id> | |
<name>Artem Bilan</name> | |
<email>[email protected]</email> | |
</developer> | |
</developers> | |
<scm> | |
<connection>scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git</connection> | |
<developerConnection>scm:git:scm:git:ssh://[email protected]:spring-projects/spring-integration-samples.git</developerConnection> | |
<url>https://github.com/spring-projects/spring-integration-samples</url> | |
</scm> | |
<repositories> | |
<repository> | |
<id>repo.spring.io.milestone</id> | |
<name>Spring Framework Maven Milestone Repository</name> | |
<url>https://repo.spring.io/libs-milestone</url> | |
</repository> | |
</repositories> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.integration</groupId> | |
<artifactId>spring-integration-stream</artifactId> | |
<version>4.0.0.RELEASE</version> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.integration</groupId> | |
<artifactId>spring-integration-ftp</artifactId> | |
<version>4.0.0.RELEASE</version> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.11</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.hamcrest</groupId> | |
<artifactId>hamcrest-all</artifactId> | |
<version>1.3</version> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.integration</groupId> | |
<artifactId>spring-integration-amqp</artifactId> | |
<version>4.0.0.RELEASE</version> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>log4j</groupId> | |
<artifactId>log4j</artifactId> | |
<version>1.2.17</version> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.mockito</groupId> | |
<artifactId>mockito-core</artifactId> | |
<version>1.9.5</version> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-test</artifactId> | |
<version>4.0.3.RELEASE</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.integration</groupId> | |
<artifactId>spring-integration-file</artifactId> | |
<version>4.0.0.RELEASE</version> | |
<scope>compile</scope> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns="http://www.springframework.org/schema/beans" | |
xmlns:int="http://www.springframework.org/schema/integration" | |
xmlns:p="http://www.springframework.org/schema/p" | |
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | |
<bean id="testService" class="org.springframework.integration.samples.advice.retry.TestService"/> | |
<int:gateway | |
service-interface="org.springframework.integration.samples.advice.retry.FileStoreRetryGateway" | |
default-request-channel="process" error-channel="failedChannel"/> | |
<int:channel id="process"/> | |
<int:service-activator input-channel="process" ref="testService" method="isExist"> | |
<int:request-handler-advice-chain> | |
<ref bean="retryAdvice"/> | |
</int:request-handler-advice-chain> | |
</int:service-activator> | |
<bean id="retryAdvice" | |
class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice" | |
p:retryTemplate-ref="retryTemplate"/> | |
<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate"> | |
<property name="backOffPolicy"> | |
<bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy" | |
p:initialInterval="2000" p:multiplier="1"/> | |
</property> | |
<property name="retryPolicy"> | |
<bean class="org.springframework.retry.policy.SimpleRetryPolicy" | |
p:maxAttempts="3"/> | |
</property> | |
</bean> | |
<int:channel id="failedChannel"/> | |
<int:transformer input-channel="failedChannel" expression="T(java.lang.Boolean).FALSE"/> | |
</beans> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.springframework.integration.samples.advice.retry; | |
import org.apache.log4j.Logger; | |
public class TestService { | |
private static Logger logger = Logger.getLogger(TestService.class); | |
private int count = 0; | |
public boolean isExist(String id){ | |
logger.info("isExist call with id " + id + " count is " + count); | |
if (count++ < 2){ | |
throw new RuntimeException("not found"); | |
} | |
return true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.springframework.integration.samples.advice.retry; | |
import static junit.framework.Assert.assertTrue; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration("classpath:META-INF/spring/integration/retry-advice.xml") | |
public class TestServiceTest { | |
@Autowired | |
private FileStoreRetryGateway gateway; | |
@Test | |
public void testProcess() throws Exception { | |
boolean isExist = gateway.isExist("id"); | |
assertTrue(isExist); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment