- 追加された行はこの色です。
- 削除された行はこの色です。
-その名の通りRetryするFW
*設定 [#wb3fe81d]
**リトライ有効化 [#ucb6a6a3]
SpringBootの起動クラスに@EnableRetryをつけておくでOK。
**リトライ対象メソッド [#hfbcfb2f]
失敗する可能性がある処理に以下のアノテーションを付与(AOPなのでfinalなクラスには使えない)。
@Retryable(value = {BarException.class, BazException.class}, maxAttempts = 10, backoff = @Backoff(delay = 500))
**リカバリー [#c494447c]
**RetryTemplateを使う場合 [#s5471e00]
@GetMapping("/retry")
public TestResponse retry() {
RetryTemplate retryTemplate = new RetryTemplate();
// リトライ設定
Map<Class<? extends Throwable>, Boolean> retryableExceptions = new HashMap<>();
retryableExceptions.put(RuntimeException.class, true);
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(3,retryableExceptions);
retryTemplate.setRetryPolicy(retryPolicy);
// リトライ付き処理
retryTemplate.execute(context -> {
System.out.println("リトライ前");
throw new RuntimeException();
});
return new TestResponse();
}