JunsuLime / spring-cloud-native-explorer

Spring cloud explorer
1 stars 0 forks source link

Spring cloud open feign 적용하기 #40

Closed JunsuLime closed 2 years ago

JunsuLime commented 2 years ago

https://github.com/OpenFeign/feign spring integration

Declarative REST Client: Feign creates a dynamic implementation of an interface decorated with JAX-RS or Spring MVC annotations

JunsuLime commented 2 years ago

Spring Cloud integrates Eureka, Spring Cloud CircuitBreaker, as well as Spring Cloud LoadBalancer to provide a load-balanced http client when using Feign.

Spring openfeign 은 spring load balancer 의 blocking mode client 를 사용한다.

Spring Cloud OpenFeign supports all the features available for the blocking mode of Spring Cloud LoadBalancer. You can read more about them in the project documentation.

http 요청 클라이언트는 아래의 친구들로 커스터마이즈 가능하다.

The OkHttpClient and ApacheHttpClient and ApacheHC5 feign clients can be used by setting feign.okhttp.enabled or feign.httpclient.enabled or feign.httpclient.hc5.enabled to true, respectively, and having them on the classpath.

JunsuLime commented 2 years ago

Feign 은

그리고 아래의 프로퍼티도 추가설정 가능

JunsuLime commented 2 years ago

Spring cloud open-feign 을 팔아보자!

  1. 선언적 프로그래밍
  2. 추후 webclient 지원
  3. timeout(conn, read), retry 등 기본 설정 가능
JunsuLime commented 2 years ago

아하 Spring open feign 의 contract 개념에 대해 한번 더 짚고 넘어가자. https://techblog.woowahan.com/2630/ https://techblog.woowahan.com/2657/ https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html

역시 한국인은 한글로 한번 훑고 영어를 보는게 ㅇㅁㅇ 영어 어렵다.

Decoder - ResponseEntityDecoder Encoder - SpringEncoder Contract - SpringMvcContract

Feign ErrorDecoder 까지 마저 보고 오늘 마무리하자. sleuth 는 어떻게 적용되는지 마저 보자.

JunsuLime commented 2 years ago

Default 는 FeignClientsConfiguration 를 통해서 적용됨

ErrorDecoder

아무것도 적용하지않았을 경우 ErrorDecoder.Default 가 사용됨 Default 적용 시 "Retry-After" 가 header 에 있을 경우 RetryableException 이 발생합니다.

Retryer

Default 로 Retryer.NEVER_RETRY 를 사용한다. 기본 retry 는 Retryer.Default 로 충분할 것으로 보임

Retryer 는 RetryableException 발생 시 동작함 Feign에서의 Exception 은 FeignException 을 상속받고있다.

JunsuLime commented 2 years ago

의문점

=====================================================

JunsuLime commented 2 years ago

Feign 간단 소개, 에러 처리와 재시도

Feign 소개

Feign 의 여러가지 설정들

FeignClientsConfiguration 에 spring.cloud.openFeign 의 Default 설정들이 있으며, 아무것도 건들지 않을 경우 해당 설정을 사용한다. FeignClientsConfiguration, Feign.Builder 를 통해 Default 값 파악 가능

에러 처리 및 재시도

SynchronousMethodHandler 를 사용해서 동작한다. Feign은 FeignException 을 최상위에 구현했으며 이를 상속 받아 여러 Exception 을 만든다.

마무리

JunsuLime commented 2 years ago

기회가 된다면 다음에

을 챙겨보자. (이번에는 여기까지로 마무리)