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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章