可以用在限时抢购的一些场景中。
spring:cloud:gateway:#设置路由:路由id、路由到微服务的uri、断言routes:- id: order_route #路由ID,全局唯一uri: http://localhost:8020 #目标微服务的请求地址和端口predicates:# 测试:http://localhost:8888/order/findOrderByUserId/1# 匹配在指定的日期时间之后发生的请求 入参是ZonedDateTime类型- After=2021-01-31T22:22:07.783+08:00[Asia/Shanghai]
获取ZonedDateTime类型的指定日期时间
ZonedDateTime zonedDateTime = ZonedDateTime.now();//默认时区// 用指定时区获取当前时间ZonedDateTime zonedDateTime2 = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
代码地址
https://gitee.com/zjj19941/ZJJ_Neaten5.10/tree/master/ZJJ_Gateway/demo03
演示
yaml配置:
predicates:# #Path路径匹配- Path=/order/**- After=2022-02-03T12:45:09.439+08:00[Asia/Shanghai]
启动下面两个服务
MallOrderApplication
MallGatewayApplication
postman发起请求: http://localhost:8888/order/findOrderByUserId/1
发现在12点44分访问的时候报404,

在12点45分访问就能访问通了


