博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring cloud gateway 内置predicate
阅读量:2216 次
发布时间:2019-05-07

本文共 1978 字,大约阅读时间需要 6 分钟。

内置的Predicate

1、请求时间匹配

  • After Route Predicate Factory
    • - After=2017-01-20T17:42:47.789-07:00[America/Denver]
    • 与2017年1月20日17:42 Mountain Time(Denver)之后的所有请求相匹配
  • Before Route Predicate Factory
    • - Before=2017-01-20T17:42:47.789-07:00[America/Denver]
    • 与2017年1月20日17:42 Mountain Time(Denver)之前的所有请求相匹配
  • After Route Predicate Factory
    • - Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]
    • 与2017年1月20日17:42之后和2017年1月21日17:42之前的任何请求相匹配

2、Cookie匹配

  • Cookie Route Predicate Factory
    • - Cookie=chocolate, ch.p
    • 匹配请求具有名为chocolatewho的值与ch.p正则表达式匹配的cookie

3、Header匹配

  • Header Route Predicate Factory
    • - Header=X-Request-Id, \d+
    • 请求头X-Request-Id其值与\d+正则表达式匹配(具有一个或多个数字的值),则此路由匹配

4、Host匹配

  • Host Route Predicate Factory
    • - Host=**.somehost.org,**.anotherhost.org
    • This route would match if the request has a Host header has the value www.somehost.org or beta.somehost.org or www.anotherhost.org.
    • - {sub}.myhost.org
    • 将URI模板变量(sub如上例中定义的)提取为名称和值的映射,并将其放在ServerWebExchange.getAttributes()带有定义的键的位置ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE

5、Method匹配

  • Method Route Predicate Factory
    • - Method=GET
    • 匹配请求方法为GET的请求

6、Path匹配

  • Path Route Predicate Factory
    • - Path=/foo/{segment},/bar/{segment}
    • This route would match if the request path was, for example: /foo/1 or /foo/bar or /bar/baz.
    • 将URI模板变量(segment如上例中定义的)提取为名称和值的映射,并将其放在ServerWebExchange.getAttributes()带有定义的键的位置ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE

7、QueryParam匹配

  • Query Route Predicate Factory
    • - Query=baz
    • This route would match if the request contained a baz query parameter.
    • - Query=foo, ba.
    • 请求包含foo其值与ba.regexp 匹配的查询参数,则此路由将匹配,因此bar并且baz将匹配

8、Remote匹配

  • RemoteAddr Route Predicate Factory
    • - RemoteAddr=192.168.1.1/24
    • This route would match if the remote address of the request was, for example, 192.168.1.10.****

配置

spring:  cloud:    gateway:      routes:      - id: after_route        uri: https://example.org        predicates:        - After=2017-01-20T17:42:47.789-07:00[America/Denver]

 

转载地址:http://qikfb.baihongyu.com/

你可能感兴趣的文章
分布式系统理论基础8:zookeeper分布式协调服务
查看>>
搞懂分布式技术1:分布式系统的一些基本概念
查看>>
搞懂分布式技术2:分布式一致性协议与Paxos,Raft算法
查看>>
搞懂分布式技术3:初探分布式协调服务zookeeper
查看>>
搞懂分布式技术4:ZAB协议概述与选主流程详解
查看>>
搞懂分布式技术5:Zookeeper的配置与集群管理实战
查看>>
搞懂分布式技术6:Zookeeper典型应用场景及实践
查看>>
搞懂分布式技术10:LVS实现负载均衡的原理与实践
查看>>
搞懂分布式技术11:分布式session解决方案与一致性hash
查看>>
搞懂分布式技术12:分布式ID生成方案
查看>>
搞懂分布式技术13:缓存的那些事
查看>>
搞懂分布式技术14:Spring Boot使用注解集成Redis缓存
查看>>
搞懂分布式技术15:缓存更新的套路
查看>>
搞懂分布式技术16:浅谈分布式锁的几种方案
查看>>
搞懂分布式技术17:浅析分布式事务
查看>>
搞懂分布式技术18:分布式事务常用解决方案
查看>>
搞懂分布式技术19:使用RocketMQ事务消息解决分布式事务
查看>>
搞懂分布式技术20:消息队列因何而生
查看>>
搞懂分布式技术21:浅谈分布式消息技术 Kafka
查看>>
后端技术杂谈1:搜索引擎基础倒排索引
查看>>