사용자 도구

사이트 도구


springframework:cloud_gateway

문서의 이전 판입니다!


Spring Cloud Gateway

  • Spring Boot / WebFlux / Reactor 기반의 Non Blocking API Gateway.
  • Zuul - Edge Service 에 대응. Java/Spring 기반 개발자들에게는 Spring Cloud Gateway 가 더 나아 보인다.
  • Java Code 기반 Routing 설정 가능

Routings

  • localhost:8080/gethttp://httpbin.org:80/get 으로 요청 라우팅
    .route(p -> p.path("/get")
      .filters(f -> f.addRequestHeader("Hello", "World"))
      .uri("http://httpbin.org:80"))
     
  • URL을 중간에 바꿔치기해서 라우팅 localhost:8080/api/v1/gethttp://httpbin.org:80/get 으로 요청 라우팅
    .route(p -> p.path("/api/v1/get")
      .filters(f -> f.setPath("/get"))
      .uri("http://httpbin.org:80"))
  • PATH 앞에 떼어내기 localhost:8080/api/httpbin/gethttp://httpbin.org:80/get
    route("httpbin", p -> p.path("/api/httpbin/**")
       .filters(f -> f.stripPrefix(2))
     .uri("http://httpbin.org:80))
    // '/api' - 1, '/httpbin' - 2 해서 2 path 건너뛰기
  • PATH Variable 정규표현식 localhost:8080/api/httpbin/get/123http://httpbin.org:80/get/123, 단 /get/abc 는 거부됨
    route("httpbin", p -> p.path("/api/httpbin/get/{num:[0-9]+}")
       .filters(f -> f.stripPrefix(2))
     .uri("http://httpbin.org:80))
  • Path Rewrite : java - Spring Cloud Gateway 2.0 forward path variable - Stack Overflow
    route("userById", t -> t.path("/users/**")
      .filters(rw -> rw.rewritePath("/users/(?<segment>.*)", "/users/${segment}"))
      .uri("http://localhost:8080/users/"))

참조

springframework/cloud_gateway.1551420089.txt.gz · 마지막으로 수정됨: 2019/03/01 15:01 저자 kwon37xi