티스토리 뷰

만약 Spring Cloud를 통해 MSA를 구성하고 있다면 Micro-Service 간 통신을 위해 

RestTemplate 또는 FeignClient를 이용할 것이다

그럼 이 세 가지 방식 중 어떤 것을 택해야 할까?

 

FeignClient는 Netflix에서 RestTemplate보다 효율적인 통신을 위해 만든 것이다

RestTemplate, FeignClient는 Synchronous, Blocking 방식이고 WebClient는 Asynchronous, NonBlocking 방식이다

R / F 하고 W는 결이 다르다 WebClient는 비동기 방식이니까 러닝 커브도 있을 것이고

간단한 토이 프로젝트에 WebClient를 적용시키는 것은 공부하려는 목적이라면야 좋지만 진검으로 사과 깎아 먹는 짓이다

또한 Spring 5부터 전통적 방식인 RestTemplate은 deprecated 예정이고 그 자리를 WebClient가 대신할 것이라 한다

더보기

Srping 5.

 

WebClient is an interface representing the main entry point for performing web requests.

It has been created as a part of the Spring Web Reactive module and will be replacing the classic RestTemplate in these scenarios. The new client is a reactive, non-blocking solution that works over the HTTP/1.1 protocol

 

아래 사진은 RestTemplate과 FeignClient의 코드 레벨에서 간단한 비교이다

RestTemplate은 핵심 코드 외에 입혀줘야 할 옷이 많지만 사용하는 메서드 레벨에서 다 끝낼 수 있다

FeignClient는 사용하는 메서드 레벨에서 한 줄로 끝날만큼 간단하지만 추가적으로 Interface를 구현해줘야한다

FeignClient를 쓰는 편이 나아보인다

 

결론은 우선 FeignClient를 이용하고 자신의 프로젝트가 너무나 비대해져 비동기 방식이 필요해진 상황에 WebClient를 도입하자

 

 

 

참고를 위해 StackOverFlow 두 글을 첨부합니다

 

 

 

WebClient vs RestTemplate

As per spring 5: WebClient is an interface representing the main entry point for performing web requests. It has been created as a part of the Spring Web Reactive module and will be replacing the

stackoverflow.com

 

 

SpringBoot FeignClient vs WebClient

I want to consume a couple of rest services. Before I have used RestTemplate, but now I want to know What is main diffrences of SpringBoot FeignClient and WebClient? when they should be used?

stackoverflow.com

 

댓글
링크
글 보관함
«   2024/05   »
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
Total
Today
Yesterday