Spring Cloud - Gateway!
Spring Cloud Gateway
https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/
마이크로 서비스에서 게이트웨이는 주로 일괄적인 보안처리, 시스템 복잡도를 숨기기 위해 리버스 프록시 형태로 많이 사용한다.
과거 Spring Cloud 에서 게이트웨이 역할을 해주는 Spring Cloud Netflix Zuul 이 deprecated 되고 Spring Cloud Gateway 가 공식적으로 게이트웨이 프로젝트로 자리잡았다.
하지만
zuul은Spring Cloud Hoxton Release를 마지막으로 더이상 지원하지 않음.
아래와 같이 spring-cloud-starter-gateway 의존성을 추가.
1 | dependencies { |
application.properties 나 java config 로 라우팅역할을 해줄 설정만 적용하면 된다.
Spring Cloud Gateway 설정에는 3가지 기본 개념이 있다.
- route
게이트 웨이 기본 요소 목적지 url 과 각종 조건 설정 - predicates
조건자, 각 요청 처리전 실행되는 로직,java8Predicate인터페이스 기반 전처리 조건 설정 - filters
필터, 각 요청/응답 값의 필터 설정,GatewayFilter의 구현체
application.properties
application.properties 파일을 통해 Spring Cloud Gateway 설정하는법
1 | server.port=8000 |
java config
위의 application.properties 를 그대로 java config 로 변환
1 |
|
Spring Cloud Gateway Actuator API
https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#actuator-api
management.endpoint.gateway.enabled=true 설정시 CRUD 를 통해 spring cloud gateway 수정이 가능하다.
ID |
HTTP Method |
Description |
|---|---|---|
globalfilters |
GET |
Displays the list of global filters applied to the routes. |
routefilters |
GET |
Displays the list of GatewayFilter factories applied to a particular route. |
refresh |
POST |
Clears the routes cache. |
routes |
GET |
Displays the list of routes defined in the gateway. |
routes/{id} |
GET |
Displays information about a particular route. |
routes/{id} |
POST |
Add a new route to the gateway. |
routes/{id} |
DELETE |
Remove an existing route from the gateway. |
1 | { |