网关流速控制

1、引入maven依赖

<dependency>
      <groupId>com.marcosbarbero.cloud</groupId>
      <artifactId>spring-cloud-zuul-ratelimit</artifactId>
      <!--<version>2.1.0.RELEASE</version>-->
      <version>1.3.2.RELEASE</version>
    </dependency>
    <!--redis依赖-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
    <!--连接池common-pool,因为不管是Jedis也好,还是Lettuce,底层都会基于commons-pool来实现连接池效果-->
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-pool2</artifactId>
    </dependency>

2、引入配置

spring:
    redis:
      host: your ip
      port: 6379
      database: 0
      password: your password
      lettuce:
        pool:
          max-active: 8
          max-idle: 8
          min-idle: 0
          max-wait: -1ms
zuul:
  ratelimit:
    enabled: true
    repository: REDIS # 使用 Redis 作为限流存储
    behind-proxy: false # 如果 Zuul 跑在代理后面,如 Nginx,则需要设置为 true
    default-policy: #可选 - 针对所有的路由配置的策略,除非特别配置了policies
      limit: 50 #可选 - 每个刷新时间窗口对应的请求数量限制
      quota: -1 #可选-  每个刷新时间窗口对应的请求时间限制(秒)
      refresh-interval: 60 # 刷新时间窗口的时间,默认值 (秒)
      type: #可选 限流方式
        - origin
        - url

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值