[英]Retry mechanism for Web Service invocation
I am invoking web service in java. 我正在用Java调用Web服务。 I have the requirement, tha if if there was error during web service invocation, the same Web service call needs to be retriggered after a certain predefined time interval for max attempts, say 5.
我有一个要求,如果在Web服务调用期间出现错误,则需要在一定的预定义时间间隔后重新触发相同的Web服务调用以进行最大尝试,例如5。
Is there any api in java I can use for this purpose? 我可以为此目的使用Java中的任何api吗?
Check this one http://aspects.jcabi.com/annotation-retryonfailure.html 选中一个http://aspects.jcabi.com/annotation-retryonfailure.html
It provides an annotation to specify the retry strategy. 它提供了注释以指定重试策略。
Spring has a retry annotation which servers the purpose Spring有一个重试注释,该注释用于目的
Step 1: Add following dependency to your POM 步骤1:将以下依赖项添加到您的POM
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.1.5.RELEASE</version>
</dependency>
Step 2: Enabling Spring Retry 步骤2:启用Spring重试
To enable Spring Retry in an application, we need to add the @EnableRetry annotation to our @Configuration class:
Ex:
@Configuration
@EnableRetry
public class AppConfig { ... }
Step 3: To add retry functionality to methods, @Retryable can be used: 步骤3:要向方法添加重试功能,可以使用@Retryable:
Ex:
@Service
public interface MyService {
@Retryable(
value = { SQLException.class },
maxAttempts = 2,
backoff = @Backoff(delay = 5000))
void retryService(String sql) throws SQLException;
...
}
Step 4.The @Recover annotation is used to define a separate recovery method when a @Retryable method fails with a specified exception: 步骤4.当@Retryable方法因指定的异常而失败时,@Recover批注用于定义单独的恢复方法:
Ex:
@Service
public interface MyService {
...
@Recover
void recover(SQLException e, String sql);
}
See Url for more details : http://www.baeldung.com/spring-retry 有关更多详细信息,请参见网址: http : //www.baeldung.com/spring-retry
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.