[Spring] spring cloud Gateway 란 ?
by 코박7
Gateway 의 흐름
- 위의 그림과 같이 msa project server 에서 요청이 있으면 Gateway 로 요청을 하고 Gateway service 는 Eureka server (discovery server) 와 통신하여 특정 서비스로 연결해주는 흐름이다.
의존성 추가
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
server.port=8100
spring.application.name=gateway
# gateway setting
spring.cloud.gateway.routes[0].id=user-service
# 포워딩할 주소, <http://localhost:8000/user> 로 들어오면 <http://localhost:50400> 으로 포워딩
spring.cloud.gateway.routes[0].uri=lb://USER
# 해당 gateway 서버의 /user/**로 들어오는 요은 user-service로 인식하겠다는 조건
spring.cloud.gateway.routes[0].predicates[0].=Path=/api/v1/users/**
# eureka client
eureka.instance.instance-id=gateway
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
eureka.instance.prefer-ip-address=true
- gateway server 도 하나의 eureka client 이기 때문에 eureka client 설정도 추가를 시켜준다.
- URI 에 lb://VEHICLE 은 Eureka Server 에 있는 application name 을 지정할 수 있다.
- 직접 주소를 입력하지 않아도 되니 유동적으로 사용 가능함.
'spring' 카테고리의 다른 글
[Spring] spring Load Balancing 이란 ? (0) | 2024.01.30 |
---|---|
[Spring] Discovery Eureka Client 란 (0) | 2023.09.10 |
[Spring] Discovery Server (Eureka Server) 란 ? (0) | 2023.09.10 |
[Spring] @NoArgsConstructor, @RequiredArgsConstructor, @AllArgsConstructor (0) | 2023.07.31 |
[Spring] 간단하게 POST 요청 보내기 (2) | 2023.07.25 |
블로그의 정보
코딩박스
코박7