Spring Cloud Gateway - 路由法则

1、 After Route Predicate Factory

输入一个参数:时间,匹配该时间之后的请求,示例配置:

1spring:
2  cloud:
3    gateway:
4      routes:
5      - id: after_route
6        uri: https://anoyi.com
7        predicates:
8        - After=2019-11-11T11:11:11.111+08:00[Asia/Shanghai]

2、Before Route Predicate Factory

输入一个参数:时间,匹配该时间之前的请求,示例配置:

1spring:
2  cloud:
3    gateway:
4      routes:
5      - id: before_route
6        uri: https://anoyi.com
7        predicates:
8        - Before=2019-11-11T11:11:11.111+08:00[Asia/Shanghai]

3、Between Route Predicate Factory

输入两个参数:时间1、时间2,匹配该时间段的请求,示例配置:

1spring:
2  cloud:
3    gateway:
4      routes:
5      - id: between_route
6        uri: https://anoyi.com
7        predicates:
8        - Between=2019-11-10T11:11:11.111+08:00[Asia/Shanghai], 2019-11-12T11:11:11.111+08:00[Asia/Shanghai]

4、Cookie Route Predicate Factory

输入两个参数:Cookie 名称、正则表达式,匹配 Cookie 中是否存在该名称且值与正则表达式匹配,示例配置:

1spring:
2  cloud:
3    gateway:
4      routes:
5      - id: cookie_route
6        uri: https://anoyi.com
7        predicates:
8        - Cookie=name, ano.i

5、Header Route Predicate Factory

输入两个参数:Header 名称、正则表达式,匹配 Header 中是否存在该名称且值与正则表达式匹配,示例配置:

1spring:
2  cloud:
3    gateway:
4      routes:
5      - id: header_route
6        uri: https://anoyi.com
7        predicates:
8        - Header=name, ano.i

6、Host Route Predicate Factory

输入一个参数:Host Name 表达式列表,匹配 Header 中 Host 字段的值,示例配置:

1spring:
2  cloud:
3    gateway:
4      routes:
5      - id: host_route
6        uri: https://anoyi.com
7        predicates:
8        - Host=**.anoyi.cn,**.anoyi.io

7、Method Route Predicate Factory

输入一个参数:HTTP Method,匹配请求方法,示例配置:

1spring:
2  cloud:
3    gateway:
4      routes:
5      - id: method_route
6        uri: https://anoyi.com
7        predicates:
8        - Method=GET

8、Path Route Predicate Factory

输入两个参数:Spring PathMatcher表达式列表、【可选】matchOptionalTrailingSeparator标识,示例配置:

1spring:
2  cloud:
3    gateway:
4      routes:
5      - id: host_route
6        uri: https://anoyi.com
7        predicates:
8        - Path=/foo/{segment},/bar/{segment}

9、Query Route Predicate Factory

输入两个参数:请求参数、【可选】正则表达式,匹配请求地址类似于 https://anoyi.com/test?hello=world&name=anoyi所包含的 request params, 示例配置:

 1# 仅匹配是否包含参数 hello
 2spring:
 3  cloud:
 4    gateway:
 5      routes:
 6      - id: query_route
 7        uri: https://anoyi.com
 8        predicates:
 9        - Query=hello
10# 匹配参数 name 是否以 ano 开头
11spring:
12  cloud:
13    gateway:
14      routes:
15      - id: query_route
16        uri: https://anoyi.com
17        predicates:
18        - Query=name, ano.*

10、RemoteAddr Route Predicate Factory

输入一个参数:IPv4 或 IPv6 地址列表,匹配请求来源的IP地址是否在该列表,示例配置:

1spring:
2  cloud:
3    gateway:
4      routes:
5      - id: remoteaddr_route
6        uri: https://anoyi.com
7        predicates:
8        - RemoteAddr=192.168.1.1/24

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值