Spring Cloud로 개발하는 마이크로서비스 애플리케이션(MSA)
API Gateway Service
API Gateway Service
API Gateway Service
- 인증 및 권한 부여
- 서비스 검색 통합
- 응답 캐싱
- 정책, 회로 차단기 및 QoS 다시 시도
- 속도 제한
- 부하 분산
- 로깅, 추적, 상관 관계
- 헤더, 쿼리 문자열 및 청구 변환
- IP 허용 목록에 추가
Netflix Ribbon
- Spring Cloud에서의 MSA간 통신
- RestTemplate
- RestTemplate restTemplate = new RestTemplate(); restTemplate.getForObject(“http://localhost:8080", User.class, 200);
- Feign Client
- @FeignClient(“stores”) @RequestMapping(method = RequestMethod.GET, value = “/stores”) List getStores(); List getStores();
- Ribbon: Client side Load Balancer
- 서비스 이름으로 호출
- Health Check
- Spring Cloud Ribbon은 Spring Boot 2.4에서 Maintenance상태
- Maintenance상태 : 새로운 기능을 추가 하지 않는다
- 비동기 처리 방식이 안 돼서 최근에는 잘 사용하지 않는다
Netflix Zuul 구현
- 구성
- First Service
- Second Service
- Netflix Zuul - Gateway
- Spring Cloud Zuul은 Spring Boot 2.4에서 Maintenance상태
- Step1) First Service, Second Service
- Spring Boot: 2.3.8
- Dependencies: Lombok, Spring Web, Eureka Discovery Client
- Step2) First Service, Second Service
- Step3) Test
- Step4) Zuul Service
- Spring Boot: 2.3.8
- Dependencies: Lombok, Spring Web, Zuul
- Step5) Zuul Service
- Step6) ZuulFilter
Spring Cloud Gateway – 기본
- 비동기 처리 방식이 가능하다
- Netty 서버가 동작
- Step1) Dependencies
- DevTools, Eureka Discovery Client, Gateway
- Step2) application.properties (or application.yml)
- Step3) Test
Spring Cloud Gateway – Filter
- Step4) Filter using Java Code – FilterConfig.java
- Step4) Filter using Java Code – FirstServiceController.java, SecondServiceController.java
- Step4) Test
- Step5) Filter using Property – application.yml
- Step5) Test
Spring Cloud Gateway – Custom Filter
- Step6) Custom Filter – CustomFilter.java
- Step6) Custom Filter – application.yml
- Step6) Custom Filter – FirstServiceController.java, SecondServiceController.java
Spring Cloud Gateway – Global Filter
- Step7) Global Filter – GlobalFilter.java
- Step7) Global Filter – application.yml
- Step7) Global Filter – Test
Spring Cloud Gateway – Custom Filter (Logging)
- Step8) Logging Filter – LoggingFilter.java
- Step8) Logging Filter – application.yml
- Step8) Logging Filter – Test
Spring Cloud Gateway – Eureka 연동
- Step1) Eureka Client 추가 – pom.xml, application.yml
- Spring Cloud Gateway, First Service, Second Service
- Step2) Eureka Client 추가 –application.yml
- Spring Cloud Gateway
- Step3) Eureka Server – Service 등록 확인
- Spring Cloud Gateway, First Service, Second Service
Spring Cloud Gateway – Load Balancer
- Step4) First Service, Second Service를각각2개씩기동
- VM Options à-Dserver.port=[다른포트]
- mvn spring-boot:run -Dspring-boot.run.jvmArguments=’-Dserver.port=9003’
- mvn clean compile package $ java -jar -Dserver.port=9004 ./target/user-service-0.0.1-SNAPSHOT.jar
- Step5) Eureka Server – Service 등록확인
- Step6) Random port 사용
- Spring Cloud Gateway, First Service, Second Service
- Step6) Post 확인 – FirstController.java
- Step6) Random port 사용
- Spring Cloud Gateway, First Service, Second Service