Spring Cloud Gateway(八):其它路由谓词工厂
本文基于 spring cloud gateway 2.0.1
6、基于Cookie的谓词工厂
CookieRoutePredicateFactory 是 Cookie 类型的路由断言工厂,接收两个参数: cookie 名字和一个正则表达式。 此谓词匹配具有给定名称且值与正则表达式匹配的cookie。
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: http://example.org
predicates:
- Cookie=chocolate, ch.p
此路由匹配请求有一个名为chocolate的cookie,其值与ch.p正则表达式匹配。
7、基于Header的谓词工厂
Header Route Predicate Factory有两个参数,标题名称和正则表达式。此谓词与具有给定名称且值与正则表达式匹配的标头匹配。
spring:
cloud:
gateway:
routes:
- id: header_route
uri: http://example.org
predicates:
- Header=X-Request-Id, \d+
如果请求具有名为X-Request-Id的标头,则该路由匹配,其值与\ d +正则表达式匹配(具有一个或多个数字的值)。
8、基于Host的谓词工厂
Host Route Predicate Factory采用一个参数:主机名模式。该模式是一种Ant样式模式“.”作为分隔符。此谓词匹配与模式匹配的Host标头。
spring:
cloud:
gateway:
routes:
- id: host_route
uri: http://www.baidu.com
predicates:
- Host=**.testhost.org
如果请求的主机头具有值 **.testhost.org,则此路由将匹配。
9、基于Method请求方法的谓词工厂
Method Route Predicate Factory采用一个参数:要匹配的HTTP方法。
spring:
cloud:
gateway:
routes:
- id: method_route
uri: http://example.org
predicates:
- Method=GET
如果请求的 Method 为 GET,则匹配该路由。
10、基于Path请求路径的谓词工厂
PathRoutePredicateFactory 是基于请求路径的路由断言工厂,接收一个参数: Spring 的 PathMatcher 模式串。
spring:
cloud:
gateway:
routes:
- id: host_route
uri: http://example.org
predicates:
- Path=/foo/{segment}
如果请求路径是 /foo/1 或者/foo/bar,将会匹配该路由。
11、基于Query请求参数的路由工厂
QueryRoutePredicateFactory 是请求参数的路由断言工厂,接收两个参数: 一个 必须的请求param 和一个可选的正则表达式。
spring:
cloud:
gateway:
routes:
- id: query_route
uri: http://example.org
predicates:
- Query=baz, ba.
如果请求中包含baz查询参数,且其值匹配 ba. 正则表达式,将会匹配该路由。
Spring Cloud Gateway(八):其它路由谓词工厂的更多相关文章
- Spring Cloud Alibaba学习笔记(18) - Spring Cloud Gateway 内置的过滤器工厂
参考:https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.1.0.RELEASE/single/spring-clou ...
- Spring Cloud Gateway的动态路由怎样做?集成Nacos实现很简单
一.说明 网关的核心概念就是路由配置和路由规则,而作为所有请求流量的入口,在实际生产环境中为了保证高可靠和高可用,是尽量要避免重启的,所以实现动态路由是非常有必要的:本文主要介绍 Spring Clo ...
- Spring cloud gateway 如何在路由时进行负载均衡
本文为博主原创,转载请注明出处: 1.spring cloud gateway 配置路由 在网关模块的配置文件中配置路由: spring: cloud: gateway: routes: - id: ...
- Spring Cloud Gateway之动态路由(数据库版)
1.实现动态路由的关键是RouteDefinitionRepository接口,该接口存在一个默认实现(InMemoryRouteDefinitionRepository) 通过名字我们应该也知道该实 ...
- Spring Cloud Alibaba学习笔记(16) - Spring Cloud Gateway 内置的路由谓词工厂
Spring Cloud Gateway路由配置的两种形式 Spring Cloud Gateway的路由配置有两种形式,分别是路由到指定的URL以及路由到指定的微服务,在上文博客的示例中我们就已经使 ...
- Spring Cloud Alibaba学习笔记(19) - Spring Cloud Gateway 自定义过滤器工厂
在前文中,我们介绍了Spring Cloud Gateway内置了一系列的内置过滤器工厂,若Spring Cloud Gateway内置的过滤器工厂无法满足我们的业务需求,那么此时就需要自定义自己的过 ...
- spring cloud gateway之filter篇
转载请标明出处: https://www.fangzhipeng.com 本文出自方志朋的博客 在上一篇文章详细的介绍了Gateway的Predict,Predict决定了请求由哪一个路由处理,在路由 ...
- 使用Spring Cloud Gateway保护反应式微服务(一)
反应式编程是使你的应用程序更高效的一种越来越流行的方式.响应式应用程序异步调用响应,而不是调用资源并等待响应.这使他们可以释放处理能力,仅在必要时执行处理,并且比其他系统更有效地扩展. Java生态系 ...
- Spring Cloud Alibaba学习笔记(17) - Spring Cloud Gateway 自定义路由谓词工厂
在前文中,我们介绍了Spring Cloud Gateway内置了一系列的路由谓词工厂,但是如果这些内置的路由谓词工厂不能满足业务需求的话,我们可以自定义路由谓词工厂来实现特定的需求. 例如有某个服务 ...
随机推荐
- C#汉字转换成全拼的拼音
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- django pk 和id用法
pk就是primary key的缩写,也就是任何model中都有的主键,那么id呢,大部分时候也是model的主键,所以在这个时候我们可以认为pk和id是完全一样的. class Student(mo ...
- git push error. ! [rejected] master -> master (non-fast-forward)
错误提示: Cheetah@xxxx MINGW64 /e/Projs/enft/data/cv_key_frame (master) $ git push To github.com:Anthony ...
- falcon 数据丢失处理方法参考
背景:使用 netstat -ano | grep ESTABLISH | grep 11883 监控 send_Q 和 recv_Q 的值,由于单次推送数据量在1w条以上,导致falcon-agen ...
- 如何避免Linux操作系统客户端登陆超时-linux命令之TMOUT=
工作中经常遇到使用ssh,telnet工具登陆Linux操作系统时,出现的超时问题,怎么处理呢? 添加下面命令: TMOUNT=
- Winserver-Exception from HRESULT: 0x800A03EC
Q: 程序在VS中手动执行没问题,但是排了JOB报异常:Exception from HRESULT: 0x800A03EC at Excel.WorkbookClass.SaveAs() A: ...
- c# 接口实现
- 前端自己导出Excel
1.导出当前页面,这是最简单的,只是导出当前页面的数据. exportData(tableid, name) { let table; let uri = 'data:application/vnd. ...
- Set的交集、差集踩坑记录
项目中我用到了Set的retainAll和removeAll两个方法取差集和交集. 用法网上都有,我也不展示了. 但是因为我是急着用,直接就照着写了,没想到出大问题了. 因为我的set是一个map的k ...
- Linux命令——ulimit
参考:https://www.cnblogs.com/kongzhongqijing/p/5784293.html