gateway断言工厂Path,Weight
一、Path路由斷言工廠
路由斷言工廠類有兩個參數,patterns(基于spring的PathMatcher)、matchTrailingSlash(是否匹配斜杠,默認:true)
spring:cloud:gateway:routes:- id: path_routeuri: https://example.orgpredicates:- Path=/red/{segment},/blue/{segment}- 支持’/foo/{*foobar}’ 和 '/{*foobar}'格式,由CaptureTheRestPathElement提供支持;
- 支持’/foo/{bar}/goo’格式,將一段變量作為路徑元素,由CaptureVariablePathElement提供支持;
- 支持’/foo/bar/goo’格式,由LiteralPathElement提供支持;
- 支持’/foo/*/goo’通配符格式,*代表至少匹配一個字符,由WildcardPathElement提供支持;
- 支持’/foo/**’ 和 /** Rest通配符格式,匹配0個或者多個目錄,由WildcardTheRestPathElement提供支持;
- 支持’/foo/??go’單字符通配符格式,一個?代表單個字符,若需要適配多個可用多個?標識,由SingleCharWildcardedPathElement提供支持;
- 支持/foo/*_*/*_{foobar}格式,由RegexPathElement提供支持;
二、Method路由斷言工廠
spring:cloud:gateway:routes:- id: method_routeuri: https://example.orgpredicates:- Method=GET,POSTMethod路由斷言工廠有一個參數Metod,指定多個支持的請求方法;支持的方法:GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
三、Weight權重路由斷言工廠
spring:cloud:gateway:routes:- id: weight_highuri: https://weighthigh.orgpredicates:- Weight=group1, 8- id: weight_lowuri: https://weightlow.orgpredicates:- Weight=group1, 2Weight權重路由斷言工廠有兩個參數group(分組名稱)和weight(權重 int類型),每組按照權重計算流量
四、After路由斷言工廠類
After路由斷言工廠類帶有一個參數datetime(是ZonedDateTime類型),此斷言工廠類判定所有請求只有發生在指定的時間之后才符合條件;
spring:cloud:gateway:routes:- id: after_routeuri: https://example.orgpredicates:- After=2022-04-20T15:35:08.721398+08:00[Asia/Shanghai]獲取帶區域時間方法如下:
public static void main(String[] args) {ZonedDateTime zbj = ZonedDateTime.now();ZonedDateTime zny = ZonedDateTime.now(ZoneId.of("America/New_York"));System.out.println(zbj);System.out.println(zny);}四、Before路由斷言工廠類
Before路由斷言工廠類只有一個ZonedDateTime類型參數datetime,所有的請求只會發生在datetime之前;
spring:cloud:gateway:routes:- id: before_routeuri: https://example.orgpredicates:- Before=2017-01-20T17:42:47.789-07:00[America/Denver]五、Between路由斷言工廠類
Between路由斷言工廠類有兩個ZonedDateTime類型參數datetime1、datetime2,請求必須發生在datetime1和datetime2之間,datetime2必須小于datetime1;
spring:cloud:gateway:routes:- id: between_routeuri: https://example.orgpredicates:- Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]六、RemoteAddr路由斷言工廠類
RemoteAddr路由斷言工廠類有一個列表類型參數sources,可以指定路由請求的IP地址;其中192.168.1.1是IP地址,24是子網掩碼;
spring:cloud:gateway:routes:- id: remoteaddr_routeuri: https://example.orgpredicates:- RemoteAddr=192.168.1.1/24GitHub地址:https://github.com/mingyang66/EmilyGateway
總結
以上是生活随笔為你收集整理的gateway断言工厂Path,Weight的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 全角字符和半角字符切换
- 下一篇: 【drawio笔记】在drawio中添加