@CircuitBreakerはすでに真=ステートフルとして@Retryを実装し、それは彼が呼び出しが失敗したどのように多くの知っている方法です。
私は、ここに最善の方法を考えて、あなたのメソッド内RetryTemplateを使用することになります。
@CircuitBreaker(maxAttempts = 2, openTimeout = 5000l, resetTimeout = 10000l)
void call() {
retryTemplate.execute(new RetryCallback<Void, RuntimeException>() {
@Override
public Void doWithRetry(RetryContext context) {
myService.templateRetryService();
}
});
}
RetryTemplateの宣言:プロジェクト内の春の再試行を有効にする
@Configuration
public class AppConfig {
@Bean
public RetryTemplate retryTemplate() {
RetryTemplate retryTemplate = new RetryTemplate();
FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
fixedBackOffPolicy.setBackOffPeriod(2000l);
retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(2);
retryTemplate.setRetryPolicy(retryPolicy);
return retryTemplate;
}
}
:
@Configuration
@EnableRetry
public class AppConfig { ... }