日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

gateway断言工厂Path,Weight

發布時間:2023/12/16 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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,POST

Method路由斷言工廠有一個參數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, 2

Weight權重路由斷言工廠有兩個參數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/24

GitHub地址:https://github.com/mingyang66/EmilyGateway

總結

以上是生活随笔為你收集整理的gateway断言工厂Path,Weight的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。