Spring工具包-limit

Spring工具包限流组件,支持全局限流和SPI扩展

Posted by guanyang on 2022-06-08
Words 257 and Reading Time 1 Minutes
Viewed Times

概览

  • 当前组件主要用于应用访问频率限制,添加注解LimitCheck即可快速接入使用
  • 默认支持基于redis实现的频率访问控制,需要应用配置StringRedisTemplate实例
  • 支持SPI方式扩展实现,接口类:org.gy.framework.limit.core.ILimitCheckService

使用指南

1
2
3
4
5
<dependency>
<groupId>org.gy.framework</groupId>
<artifactId>spring-base-limit</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>

配置说明

  1. 需要在启动类添加@EnableLimitCheck注解

    1
    2
    //如果应用配置多个StringRedisTemplate,需要注入指定bean,启动类添加如下注解,注意修改bean名称:
    @EnableLimitCheck(redisTemplateName = "stringRedisTemplate")
  2. 注解调用示例如下,支持Spel表达式

    1
    2
    3
    4
    5
    //当前示例场景:300秒只能调用1次
    @LimitCheck(key = "'GY:LOCK:TEST:' + #user.name", limit = 1, time = 300)
    public void test(User user){
    System.out.println("------------>>>>>>>>"+user);
    }

If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !

...

...

00:00
00:00