SpringCloud-Gateway的Predicate(Day8)

Predicate简介

  • Spring Cloud Gateway将路由匹配作为Spring WebFlux HandlerMapping基础架构的一部分。
  • Spring Cloud Gateway包括许多内置的Route Predicate工厂。所有这些Predicate都与HTTP请求的不同属性匹配。多个RoutePredicate工厂可以进行组合。
  • Spring Cloud Gateway创建Route对象时,使用RoutePredicateFactory 创建 Predicate对象,Predicate 对象可以赋值给Route。Spring Cloud Gateway包含许多内置的Route Predicate Factories。
    所有这些谓词都匹配HTTP请求的不同属性。多种谓词工厂可以组合,并通过逻辑and。

The After Route Predicate Factory(规定时间之后才能请求)

spring:
  application:
    name: cloud-gateway-service
  cloud:
    gateway:
      routes:
        - id: getPaymentById
          uri: lb://CLOUD-PAYMENT-SERVICE
          predicates:
            - Path=/payment/get/**
            - After=2021-12-13T17:42:47.789-07:00[America/Denver]

获得指定格式的时间戳字符串

import java.time.ZonedDateTime;

public class Test {

    public static void main(String[] args) {
        ZonedDateTime zbt = ZonedDateTime.now();
        // 2021-12-13T17:22:35.259+08:00[Asia/Shanghai]
        System.out.println(zbt);
    }

}

The Between Route Predicate Factory(指定时间范围内才能请求)

spring:
  application:
    name: cloud-gateway-service
  cloud:
    gateway:
      routes:
        - id: getPaymentById
          uri: lb://CLOUD-PAYMENT-SERVICE
          predicates:
            - Path=/payment/get/**
            - Between=2021-12-13T17:22:35.259+08:00[Asia/Shanghai], 2021-12-13T17:42:47.789-07:00[America/Denver]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值