一、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相关推荐

  1. Gateway断言工厂配置

    一.路由配置方式 路由配置方式: 基于代码的的配置方式 基于真实 URI的配置方式 基于微服务 URI的配置方式 下面示例最常用的基于微服务URI的配置方式. 1.Gateway与注册中心相结合的路由 ...

  2. Gateway网关-路由断言工厂

    断言工厂 我们在配置文件中写的断言规则只是字符串,这些字符串会被Predicate Factory读取并处理,转变为路由判断的条件 例如Path=/user/**是按照路径匹配,这个规则是由 org. ...

  3. Spring Cloud Gateway之路由断言工厂篇

    1. 背景 最近,需要提升系统安全性,市面上有很多款网关服务的技术方案,最终选择了Spring Cloud Gateway. 2. Spring Cloud Gateway工作机制 官网配图: 客户端 ...

  4. SpringCloud 组件Gateway服务网关【断言工厂过滤器工厂】

    目录 1:断言工厂 2:过滤器工厂 2.1:路由过滤器的种类 2.2:请求头过滤器 2.3:默认过滤器 2.4:总结 1:断言工厂 路由断言工厂Route Predicate Factory 路由配置 ...

  5. Spring Cloud Gateway 路由转发之After(Before)路由断言工厂使用

    前言 本文旨在介绍After(Before)路由断言工厂使用,以此类推可以使用其他路由断言工厂 案例 1.概念 网关简单的说就是提供一个对外统一的API入口和出口,统管企业对外的所有API出口.一般来 ...

  6. Gateway - Path、Query、RemoteAddr路由断言工厂

    一.PathRoutePredicateFactory 匹配请求路径. 源码解析 用法 二.QueryRoutePredicateFactory 匹配请求的查询参数. 源码 用法 三.RemoteAd ...

  7. Spring Cloud Gateway路由断言实战——RemoteAddr路由断言工厂

    一 源码位置 https://github.com/cakin24/spring-cloud-code/tree/master/ch17-2/ch17-2-9-gateway 二 关键代码 packa ...

  8. Spring Cloud Alibaba - 25 Gateway-路由断言工厂Route Predicate Factories谓词工厂示例及源码解析

    文章目录 官网 The After Route Predicate Factory 小栗子 AfterRoutePredicateFactory源码 The Before Route Predicat ...

  9. 《深入理解 Spring Cloud 与微服务构建》第十一章 服务网关

    <深入理解 Spring Cloud 与微服务构建>第十一章 服务网关 文章目录 <深入理解 Spring Cloud 与微服务构建>第十一章 服务网关 一.服务网关简介 二. ...

  10. Gateway路由谓词工厂实例

    本文编写一些测试例子来说下gateway中的内置路由谓词工厂. 文章目录 环境准备 常见路由谓词工厂 实战部分 路径-谓词工厂 后时刻-谓词工厂 前时刻-谓词工厂 时间段-谓词工厂 cookie-谓词 ...

最新文章

  1. 科技创新2030---“新一代人工智能”重大项目2018年度项目申报指南征稿
  2. 系统学习Spring之Spring in action(二)
  3. Oracle Lsnrctl - 关于oracle监听器的命令和解释
  4. 限制python内存上限_Python限制内存和CPU使用量的方法(Unix系统适用)
  5. 04--MySQL自学教程:数据库MySQL--【数据库DB】和【数据库管理系统DBMS】简介
  6. java 回调(callback)函数简介.
  7. 【python教程】append()与extend()方法的区别教程
  8. 【bzoj1222】[HNOI2001]产品加工 背包dp
  9. 通过ng-change选择ng-object
  10. 四川地震,物联网地震预警系统立功了
  11. Java学习之基本概念
  12. linux 如何重建mbr,重建mbr要不要勾选
  13. 按Enter键调用登录按钮
  14. CobaltStrike(CS)与MetasploitFramework(MSF)联动
  15. 电脑重装系统后Win7打印机无法打印该如何处理?
  16. 爬虫爬取斗鱼小姐姐直播间的封面
  17. javah 类com.xxxx.xxxx 找不到问题解决方法
  18. 截至到2022年12月12日,知网最新改进 YOLO 核心论文合集 | 22篇创新点速览
  19. fib函数用python编写求第n项_深市收盘价如何确定
  20. Endnote软件改变文献引用格式报错-解决方案

热门文章

  1. 混合云存储跨云灾备方案之跨云备份
  2. thrift 编译报错 undefined reference
  3. 【Python实战】手把手超详细教程教你Scrapy爬达盖尔社区,有彩蛋
  4. 如何把录音生成二维码,用微信扫一下就能听?分享语音音频转二维码的方法和技术原理
  5. X光,CT扫描,核磁共振的区别
  6. 代理服务器和反向代理服务器
  7. CDD数据库文件制作(三)——DID
  8. GAMS系列分享13——综合能源系统——包含储能的单能源枢纽模型
  9. mysql 1236 bug_Mysql:1236常见错误
  10. 如何快捷地下载知乎中的视频