File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
src/main/java/com/oronaminc/join/global/config Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ dependencies {
6363 // caffeine
6464 implementation ' com.github.ben-manes.caffeine:caffeine'
6565
66+ implementation ' org.springframework.retry:spring-retry:2.0.12'
6667}
6768
6869tasks. named(' test' ) {
Original file line number Diff line number Diff line change 1+ package com .oronaminc .join .global .config ;
2+
3+ import java .time .Duration ;
4+
5+ import org .springframework .boot .web .client .RestTemplateBuilder ;
6+ import org .springframework .context .annotation .Bean ;
7+ import org .springframework .context .annotation .Configuration ;
8+ import org .springframework .http .client .ClientHttpRequestInterceptor ;
9+ import org .springframework .retry .policy .SimpleRetryPolicy ;
10+ import org .springframework .retry .support .RetryTemplate ;
11+ import org .springframework .web .client .RestTemplate ;
12+
13+ @ Configuration
14+ class RestTemplateConfig {
15+
16+ @ Bean
17+ public RestTemplate restTemplate () {
18+ return new RestTemplateBuilder ()
19+ .connectTimeout (Duration .ofSeconds (5 ))
20+ .readTimeout (Duration .ofSeconds (5 ))
21+ .additionalInterceptors (clientHttpRequestInterceptor ())
22+ .build ();
23+ }
24+
25+ // 3번 재시도
26+ public ClientHttpRequestInterceptor clientHttpRequestInterceptor () {
27+ return (request , body , execution ) -> {
28+ RetryTemplate retryTemplate = new RetryTemplate ();
29+ retryTemplate .setRetryPolicy (new SimpleRetryPolicy (3 ));
30+ try {
31+ return retryTemplate .execute (context -> execution .execute (request , body ));
32+ } catch (Throwable throwable ) {
33+ throw new RuntimeException (throwable );
34+ }
35+ };
36+ }
37+
38+ }
You can’t perform that action at this time.
0 commit comments