Github 소스코드
Spring Cloud Gateway를 이용한 API Gateway Service 구현 및 Routing test
- API Gateway 프로젝트 설정
- Spring-boot: 2.4.x
- Dependency
- Lombok, Spring Cloud Routing(Gateway), Eureka Client
- 테스트를 위한 서비스 프로젝트 설정
- Spring-boot: 2.4.x
- Dependency
- Spring web, Eureka Client
- Eureka Server는 이전 포스트에서 구현한 서버를 사용
Routing
- API gateway service yml설정
- predicates에서 path=/first-service/**로 설정한 부분은 http://localhost:8000/first-service/ 이하로 들어오는 모든 요청을 uri에 설정된 곳으로 포워딩시킨다는 의미이다.
- 즉, http://localhost:8000/first-service/welcome은 http://localhost:8081/first-service/welcome으로 요청이 포워딩 된다.
- Routing Test
- first-service와 second-service에 거의 동일한 welcome메서드가 구현되어 있다.
- 테스트를 위해 각 서비스의 random port 설정을 지우고 first-service는 8081, second-service는 8082포트로 설정하였다.
- gateway service와 2개 테스트 서비스를 모두 구동시키고 테스트를 진행한다. (postman 사용)
- http://localhost:8000/first-service/welcome
- http://localhost:8000/second-service/welcome

- gateway service를 통해 first-service와 second-service로 라우팅에 성공 :)
- http://localhost:8000/first-service/welcome
'Spring Cloud' 카테고리의 다른 글
| 패스트캠퍼스 챌린지 30일차 - Spring Cloud 1 (0) | 2021.10.05 |
|---|---|
| 🌱 Spring Cloud - MSA간 통신 (RestTemplate, Feign Client) 🌱 (0) | 2021.08.20 |
| 🌱 Spring Cloud - API Gateway Service (Load Balancing) 🌱 (0) | 2021.08.20 |
| 🌱 Spring Cloud - Service Discovery (Netflix Eureka) 🌱 (0) | 2021.08.20 |



