相关文章推荐
另类的人字拖  ·  react 使用 useEffect ...·  2 年前    · 
豪爽的饭盒  ·  我的Neo4j探索之旅 - ...·  2 年前    · 
踢足球的围巾  ·  LaTeX排版问题? - 知乎·  2 年前    · 

The GlobalFilter interface has the same signature as GatewayFilter . These are special filters that are conditionally applied to all routes. (This interface and usage are subject to change in future milestones).

The LoadBalancerClientFilter looks for a URI in the exchange attribute ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR . If the url has a lb scheme (ie lb://myservice ), it will use the Spring Cloud LoadBalancerClient to resolve the name ( myservice in the previous example) to an actual host and port and replace the URI in the same attribute. The unmodified original url is appended to the list in the ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR attribute. The filter will also look in the ServerWebExchangeUtils.GATEWAY_SCHEME_PREFIX_ATTR attribute to see if it equals lb and then the same rules apply.

application.yml.

spring:
  cloud:
    gateway:
      routes:
      - id: myRoute
        uri: lb://service
        predicates:
        - Path=/service/**

[Note] Note

By default when a service instance cannot be found in the LoadBalancer a 503 will be returned. You can configure the Gateway to return a 404 by setting spring.cloud.gateway.loadbalancer.use404=true .

[Note] Note

The isSecure value of the ServiceInstance returned from the LoadBalancer will override the scheme specified in the request made to the Gateway. For example, if the request comes into the Gateway over HTTPS but the ServiceInstance indicates it is not secure, then the downstream request will be made over HTTP . The opposite situation can also apply. However if GATEWAY_SCHEME_PREFIX_ATTR is specified for the route in the Gateway configuration, the prefix will be stripped and the resulting scheme from the route URL will override the ServiceInstance configuration.