Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- MST
- 쿼리
- Intellj
- 백준
- 자바
- JPA
- 코딩
- 알고리즘
- 데이터베이스
- feign
- Spring Cloud
- 오라클
- 디자인 패턴
- Jenkins
- 페이징
- Spring Cloud Feign
- Kafka
- 자료구조
- 운영체제
- Spring
- SQL
- golang
- aws
- 클라우드
- Spring Boot
- PL/SQL
- db
- DP
- retry
- MVC
Archives
- Today
- Total
justgo_developer
[Feign] feign retry customize 본문
728x90
반응형
Spring Cloud Feign retry customize
기본적으로 Spring Cloud Feign retry 대상은 IO Exception이다.
IO Exception이란
입출력 동작 실패 또는 인터럽트 시 발생하는 Exception
ErrorDecoder 인터페이스를 직접 구현하여 에러 코드별로 처리 할수 있다.
retry 대상이 아닌 에러 코드를 retry 처리 하려면 아래와 같이 해당 코드에 RetryableException 예외를 발생시켜주면 된다.
- yml 설정에 feign.client.config.feignName.errorDecoder에 ErrorDecoder 인터페이스를 직접 구현한 클래스 경로를 추가해준다.
package com.study.springcloud;
import feign.Response;
import feign.RetryableException;
import feign.codec.ErrorDecoder;
public class KakaoFeignClientErrorDecoder implements ErrorDecoder {
private final ErrorDecoder defaultErrorDecoder = new Default();
@Override
public Exception decode(String s, Response response) {
System.out.println("Error decode Test");
if (404 == response.status()) {
return new RetryableException(404, response.reason(), response.request().httpMethod(), null, response.request());
}
return defaultErrorDecoder.decode(s, response);
}
}
feign:
hystrix:
enabled: true
client:
config:
default:
connectTimeout: 10000
readTimeout: 10000
loggerlevel: BASIC
kakao-open-api: # FeignClient에서 name 설정값으로 준 값
errorDecoder: com.study.springcloud.KakaoFeignClientErrorDecoder
connectTimeout: 10000
readTimeout: 10000
loggerLevel: BASIC
728x90
404 에러 코드로 테스트를 해보겠다.
기본적으로 404 에러는 IO Exception이 아니여서 retry 대상이 아니다. 따라서 retry 처리가 되지 않는다.
2021-09-09 10:45:36.646 DEBUG 7244 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] ---> GET https://dapi.kakao.com/v2/search/web2?query=SSG HTTP/1.1
2021-09-09 10:45:36.867 DEBUG 7244 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] <--- HTTP/1.1 404 Not Found (218ms)
2021-09-09 10:45:36.874 ERROR 7244 --- [akao-open-api-1] c.s.s.KakaoOpenApiClientFallbackFactory : Feign Client Error : [404 Not Found] during [GET] to [https://dapi.kakao.com/v2/search/web2?query=SSG] [KakaoOpenApiClient#searchDaumWeb(String)]: [{"errorType":"ResourceNotFound","message":"'GET /search-open/v2/web2' is not matched"}]
하지만, 위의 예시대로 404 에러코드일때 강제로 RetryableException 예외를 발생시키면
retry 처리가 되는 것을 확인 할 수 있다.
2021-09-09 10:47:13.867 DEBUG 10432 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] ---> GET https://dapi.kakao.com/v2/search/web2?query=SSG HTTP/1.1
2021-09-09 10:47:14.068 DEBUG 10432 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] <--- HTTP/1.1 404 Not Found (197ms)
Error decode Test
2021-09-09 10:47:14.224 DEBUG 10432 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] ---> RETRYING
2021-09-09 10:47:14.224 DEBUG 10432 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] ---> GET https://dapi.kakao.com/v2/search/web2?query=SSG HTTP/1.1
2021-09-09 10:47:14.234 DEBUG 10432 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] <--- HTTP/1.1 404 Not Found (10ms)
Error decode Test
2021-09-09 10:47:14.461 DEBUG 10432 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] ---> RETRYING
2021-09-09 10:47:14.461 DEBUG 10432 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] ---> GET https://dapi.kakao.com/v2/search/web2?query=SSG HTTP/1.1
2021-09-09 10:47:14.473 DEBUG 10432 --- [akao-open-api-1] c.study.springcloud.KakaoOpenApiClient : [KakaoOpenApiClient#searchDaumWeb] <--- HTTP/1.1 404 Not Found (12ms)
Error decode Test
2021-09-09 10:47:14.479 ERROR 10432 --- [akao-open-api-1] c.s.s.KakaoOpenApiClientFallbackFactory : Feign Client Error : Not Found
728x90
반응형
'IT > Spring Cloud' 카테고리의 다른 글
[Feign] Spring Cloud Feign Response 객체 (1) | 2023.10.05 |
---|---|
[Feign] Feign 사용중 411 "Length Required" 에러 (0) | 2023.10.05 |
[Feign] Hystrix 사용시 request 실패 (0) | 2023.10.05 |
[Feign] Spring Cloud Feign 추가 (timeout, retry, logging) (2) | 2023.10.05 |
[Feign] Spring Cloud Feign fallback (0) | 2023.10.05 |