我试着把可能的最简单的重试方案归纳下来。重试在执行时被忽略。
Application.java:
@SpringBootApplication
@EnableRetry
public class Application extends SpringBootServletInitializer {
//...这是在服务类中的:
public Boolean processItem() {
Long id = 999L;
try {
retrieveItemWithRetry(id);
return true;
} catch (NoResultException e) {
return false;
}
}
@Retryable(include=NoResultException.class, backoff = @Backoff(delay = 500, maxDelay = 3000), maxAttempts = 5)
private void retrieveItemWithRetry(Long id) {
retrieveItem(id);
}
private OrderRequest retrieveItem(Long id) {
throw new NoResultException();
} 发布于 2017-01-26 22:22:03
对@Retryable方法的内部调用(在同一个类中)是不可还原的;请参阅昨天的my answer here,这说明了原因。
此外,@Retryable方法必须是公共的。
https://stackoverflow.com/questions/41883812
复制相似问题