Spring Cloud Gateway 3 内置Filter
2021-05-13 03:27
标签:mil response thread gateway netflix example 转发 最大 url Spring Cloud Gateway中内置了很多过滤器,实现类有二十多个; 分类几类: 给请求加上一条header信息; 给请求加上Paramter参数 Spring Cloud Gateway 的RewritePath可以替换Zuul的StripPrefix; 对网关的响应添加Header 用于去除url的前缀 用于添加url前缀 请求出现异常是进行重试 参数: 进行服务熔断 降级 Hystrix过滤器还可以接受可选fallbackUri参数。当前,仅forward:支持计划的URI。如果调用了后备,则请求将转发到与URI匹配的控制器。以下示例配置了这种后备: /incaseoffailureusethis调用Hystrix后备时,它将转发到URI。请注意,此示例还演示了(可选)Spring Cloud Netflix Ribbon负载平衡(lb在目标URI上定义了前缀)。 主要方案是对fallbackUri网关应用程序中的内部控制器或处理程序使用。但是,您还可以将请求重新路由到外部应用程序中的控制器或处理程序,如下所示: 要为前面显示的示例路由设置五秒钟的超时时间,可以使用以下配置: Spring Cloud Gateway 3 内置Filter 标签:mil response thread gateway netflix example 转发 最大 url 原文地址:https://www.cnblogs.com/chenglc/p/13131926.htmlSpring Cloud Gateway 内置Filter
AddRequestHeader
spring:
cloud:
gateway:
routes:
- id: add_request_header_route
uri: https://example.org
filters:
- AddRequestHeader=X-Request-red, blue
AddRequestParameter
spring:
cloud:
gateway:
routes:
- id: add_request_parameter_route
uri: https://example.org
filters:
- AddRequestParameter=key,value
RewritePath
修改转发的路径spring:
cloud:
gateway:
routes:
- id: rewritepath_route
uri: https://example.org
predicates:
- Path=/red/**
filters:
- RewritePath=/red(?
AddResponseHeader
spring:
cloud:
gateway:
routes:
- id: add_response_header_route
uri: https://example.org
filters:
- AddResponseHeader=X-Response-Red, Blue
StripPrefix
spring:
application:
name: sc-gateway-server
cloud:
gateway:
discovery:
locator:
enabled: false
lowerCaseServiceId: true
routes:
- id: service-hi
uri: lb://SERVICE-HI
predicates:
- Path=/demo/**
- Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2021-01-21T17:42:47.789-07:00[America/Denver]
- Header=key,value
- Method=GET,POST
# - Cookie=mycookie,mycookievalue
# - After=2017-01-20T17:42:47.789-07:00[America/Denver]
# - Before=2020-01-20T17:42:47.789-07:00[America/Denver]
filters:
- StripPrefix=1
PrefixPath
spring:
cloud:
gateway:
routes:
- id: prefixpath_route
uri: https://example.org
filters:
- PrefixPath=/mypath
Retry
spring:
cloud:
gateway:
routes:
- id: retry_test
uri: http://localhost:8080/flakey
predicates:
- Host=*.retry.com
filters:
- name: Retry
args:
retries: 3
statuses: BAD_GATEWAY
methods: GET,POST
backoff:
firstBackoff: 10ms
maxBackoff: 50ms
factor: 2
basedOnPreviousValue: false
Hystryix
spring:
cloud:
gateway:
routes:
- id: hystrix_route
uri: https://example.org
filters:
- Hystrix=myCommandName
spring:
cloud:
gateway:
routes:
- id: hystrix_route
uri: lb://backing-service:8088
predicates:
- Path=/consumingserviceendpoint
filters:
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/incaseoffailureusethis
- RewritePath=/consumingserviceendpoint, /backingserviceendpoint
spring:
cloud:
gateway:
routes:
- id: ingredients
uri: lb://ingredients
predicates:
- Path=//ingredients/**
filters:
- name: Hystrix
args:
name: fetchIngredients
fallbackUri: forward:/fallback
- id: ingredients-fallback
uri: http://localhost:9994
predicates:
- Path=/fallback
hystrix.command.fallbackcmd.execution.isolation.thread.timeoutInMilliseconds: 5000
文章标题:Spring Cloud Gateway 3 内置Filter
文章链接:http://soscw.com/essay/84951.html