Programming/Java, Spring
[Spring Cloud] Users MicroService를 Api Gateway에 등록하기
Renechoi
2023. 5. 31. 21:27
간단하게 UserService를 구현하고 이를 API Gateway에 등록해보자.
구현 코드
https://github.com/renechoi/msa-with-springcloud/commit/09d9da6fd3a937c888ee4f839f0d6216dd680965
feat: user-service 구현 · renechoi/msa-with-springcloud@09d9da6
- entity, service, dto, repository, controller - create - password encoding
github.com
API Gateway 서버의 yml 파일에 다음과 같이 추가해준다.
routes:
- id: user-service
uri: lb://USER-SERVICE
predicates:
- Path=/user-service/**
기본 포트 사용시
정상적으로 discovery 서비스에 등록이 되었다면 다음과 같은 포트 + 주소 입력시 반환이 되어야 한다.
User Service의 Uri 와 API Gateway의 Uri 가 다르기 때문에 이런 문제가 생겼다.
API Gateway
=> /user-service 가 들어오면 //lb -> USER-SERVICE 로 포워딩
그런데 현재 User Service의 컨트롤러에는 순전히 /health-check라고 등록되어 있다
이제 8000번으로 접속해도 접속이 된다.
반응형