静雄桑 2022-03-02 17:15
浏览 148
已结题

spring-cloud-starter-gateway 限流无效

问题遇到的现象和发生背景

写了一个网关,路由功能正常,但是限流功能一直不生效,引入的spring-cloud-starter-gateway版本也从2.2.1换到2.2.9,但是限流始终不生效,不知道有没有大lao能帮忙看一下,下面贴上代码

问题相关代码,请勿粘贴截图

引入的依赖:

         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
        </dependency>

        <!--gateway-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
            <version>2.2.3.RELEASE</version>
        </dependency>
spring:
  cloud:
    gateway:
      # 路由集合
      routes:
        #payment_route路由的ID,没有固定规则但要求唯一,建议配合服务名
        - id: powerrecord-server
          #匹配后提供服务的路由地址
          uri: lb://powerrecord
          # 断言,路径相匹配的进行路由
          predicates: 
            - Path=/server/**
            #- After=2020-02-21T15:51:37.485+08:00[Asia/Shanghai]
            #- Cookie=username,zzyy
            #- Header=X-Request-Id, \d+  # 请求头要有X-Request-Id属性并且值为整数的正则表达式
          filters:
            - name: RequestRateLimiter
              args:
                # 令牌桶每秒填充平均速率
                redis-rate-limiter.replenishRate: 1
                # 令牌桶的上限
                redis-rate-limiter.burstCapacity: 1
                # 使用SpEL表达式从Spring容器中获取Bean对象
                key-resolver: '#{@ipKeyResolver}'
  redis:
    host: xx.xx.xx.xx
    port: 6388
    password: ENC(+I5Y1D9DQ1kXC+9yg8QQdga8vV4QGLsTiVxtiizoXapzMHu9L42OcTkE6v3x6BAP)
@Configuration
public class LimitConfiguration {

    /**
     * 按ip限流
     */
    @Bean(value = "ipKeyResolver")
    public KeyResolver ipKeyResolver() {
        System.out.println("##############ipKeyResolver########################");
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
    }
}

@SpringBootApplication
@EnableDiscoveryClient
public class PRGatewayApplication {
    public static void main(String[] args) {
        System.setProperty("jasypt.encryptor.password", ConstantsInterface.JASYPT_ENCRYPTOR_PASSWORD);
        SpringApplication.run(PRGatewayApplication.class, args);
    }
}

运行结果及报错内容

无报错,连续点击发送请求,限流不生效

我的解答思路和尝试过的方法

更换spring-cloud-starter-gateway版本,使用其他自定义限流方式,目前用过的方法都无效

我想要达到的结果

可以正常起到限流作用

  • 写回答

1条回答 默认 最新

  • 有问必答小助手 2022-03-03 17:43
    关注

    你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


    本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


    因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。

    评论

报告相同问题?

问题事件

  • 系统已结题 3月10日
  • 创建了问题 3月2日

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?