Gateway 常用的 Predicate

Gateway 常用的 Predicate
Gateway 常用的 Predicate
上面用的path 只是predicate 中的一个,只要使predicates为true 就访问,false不访问。

Route PredicateFactories
Gateway 常用的 Predicate
SpringCloud Gateway将路由匹配作为Spring WebFlux HandlerMapping基础架构的一部分。
SpringCloud Gateway包括许多内置的RoutePredicate工厂。所有这些Predicate都与HTTP请求的不同属性匹配。多个Route Predicate工厂可以进行组合。

SpringCloud Gateway创建Route对象时,使用RoutePredicateFactory创建Predicate对象,Predicate对象可以赋值给Route。SpringCloud Gateway包括许多内置的Route Predicate Factories。

所有这些谓词都匹配HTTP请求的不同属性。多种谓词工厂可以组合,并通过逻辑and。

有哪几种?
Gateway 常用的 Predicate
After、Before、Between
yml配置
Gateway 常用的 Predicate
但这是美国时间,需要转成亚洲时间,转换:
Gateway 常用的 Predicate
替换成这个时间,并往后调一小时
Gateway 常用的 Predicate
只有在这个点之后才能被访问,否则是false,不能访问。那我们来看一下访问情况
Gateway 常用的 Predicate
After是在时间之后,Before是在时间之前,Between是在之间,需要传两个时间,就不详细写了
Cookie
Gateway 常用的 Predicate
修改yml
Gateway 常用的 Predicate
重启9527,使用curl 命令测试(curl是postman 图形化界面的命令)
启动 cmd命令界面

不带cookie访问:
Gateway 常用的 Predicate
404 not found不让访问,再来看带cookie:
Gateway 常用的 Predicate
这样,时间上匹配且带着cookie就能访问了。

其余predicate方式不再叙述,可自行官网