티스토리 뷰
OpenFeign
Netflix에서 개발된 Java 의 Http Client Binder. 선언적으로 HTTP 요청을 생성 해주는 라이브러리다.
즉, 인터페이스에 어노테이션을 추가하는 정도의 코드를 통해 통신 로직을 작성할 수 있다.
적용하기
전제
- Eureka를 이용한 서비스 디스커버리가 존재한다.
Server
Setting
1. 의존성 추가

2. @EnableFeignClients 어노테이션을 추가.

마이크로 서비스간 요청받을 API 작성

Client
Setting
1. 의존성 추가

- Sprinb Boot Stater Web, Eureka-Client, Openfeign 의존성을 추가한다.
2. @EnableFeignClients 어노테이션을 추가.

Controller

Feign 을 활용한 선언적 HTTP Client Binder

- @FeignClient 를 통해 연결할 MICRO SERVICE의 Application Name을 지정해준다.
- Cotroller에서 클라이언트에서의 요청을 매핑하는 방식과 동일한 형태로 내 요청을 바인딩 해준다.
- 연결된 Micro Service에 바인딩 해준 요청을 전송해줄 수 있다.
결과

과정
- Order Micro Service 에 GET: /order/1 에 매핑되는 API를 요청한다.
- Order Service는 User name 확인을 위해 User MicroService에 GET: /user/2 를 호출한다.
- OpenFeign 라이브러리를 통해 런타임 이후 생성된 통신 로직을 통해 User Service로 부터 응답을 받는다..
- Order Service는 클라이언트에게 응답한다.
느낀점
최근 회사 에서 안드로이드 개발자분과 페어코딩을 진행하면서 Retrofit2 를 통해 API 통신을 하는 내용을 본 적이 있는데, 그 내용과 비슷해 보인다. 추가로 마치 마이크로 서비스가 분리된 것이 아닌 모놀리틱한 코드를 작성한 것 처럼 통신을 구성할 수 있다는 점이 굉장히 섬세하고 신경써서 만들었구나 라는 생각이 들게한다.
전체 코드
참조
GitHub - OpenFeign/feign: Feign makes writing java http clients easier
Feign makes writing java http clients easier. Contribute to OpenFeign/feign development by creating an account on GitHub.
github.com
Spring Cloud OpenFeign
We welcome contributions. You can read more on how to contribute to the project here.
spring.io
Introduction to Spring Cloud OpenFeign | Baeldung
Feign makes writing web service clients easier with pluggable annotation support, which includes Feign annotations and JAX-RS annotations.
www.baeldung.com
Spring Cloud - Synchronous Communication with Feign
Spring Cloud - Synchronous Communication with Feign Introduction In a distributed environment, services need to communicate with each other. The communication can either happen synchronously or asynchronously. In this section, we will look at how services
www.tutorialspoint.com
'BackEnd > Spring' 카테고리의 다른 글
[Spring Cloud] API Gateway Pre&Post Filter 설정 (0) | 2022.09.06 |
---|---|
WebSocket으로 Echo서버 구현하기 with.Spring boot (0) | 2022.09.06 |
Spring Cloud는 OOO이다. (0) | 2022.08.30 |
[Spring Cloud]Config Server로 구성 관리및 동적으로 설정 적용 (0) | 2022.08.29 |
Spring Boot를 Jar로 패키징 하기 (0) | 2022.08.18 |
- Total
- Today
- Yesterday
- 메모리 파편화
- pool
- pass by value
- 객체 풀
- 뾰족함
- 수평 분할
- Sticky Session
- 육각형 아키텍처
- 외부 단편화
- java
- ATDD
- multimap
- 컴포짓 패턴
- Session
- 내부 단편화
- Memory Fragmentation
- 동적 디스패치
- 수직 분할
- 동적 타입 언어
- Object Pool
- 정적 타입 언어
- 클린 아키텍처
- SpringBoot 2.2
- RestAssured
- pass by reference
- OOP
- Clean Architecture
- 메모리 단편화
- 세션 불일치
- 장애 해결기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |