我试图将最简单的重试方案归结为可能。执行时会忽略重试。
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();
}