客户端向Spring Cloud Gateway发出请求。如何将请求和路由进行匹配,这个时候就用到 Predicate,它决定了请求由哪个路由处理。
Predicate来自于java8的接口。Predicate 接受一个输入参数,返回一个布尔值结果。该接口包含多种默认方法来将Predicate组合成其他复杂的逻辑(比如:与,或,非)。可以用于接口请求参数校验、判断新老数据是否有变化需要进行更新操作。add–与、or–或、negate–非。
Spring Cloud Gateway内置了许多Predicate,这些Predicate的源码都在org.springframework.cloud.gateway.handler.predicate
包中。
1、AfterRoutePredicateFactory
时间类型的Predicate (AfterRoutePredicateFactory BeforeRoutePredicateFactory BetweenRoutePredicateFactory),当只有满足特定时间要求的请求会进入到此predicate中,并交由router处理。
spring:
cloud:
gateway:
routes:
- id: after_route
uri: http://example.org
predicates:
- After=2017-01-20T17:42:47.789-07:00[America/Denver]
predicates:
- After=2017-01-20T17:42:47.789-07:00[America/Denver]
会被解析成PredicateDefinition对象 (name =Af