啥也不说了,上代码先:
https://github.com/tangaiyun/redislimiter-spring-boot
或
https://gitee.com/aiyuntang/redislimiter-spring-boot
redislimiter-spring-boot
一个优秀的分布式spring boot/Spring Cloud API限流框架,特别适合微服务架构.
快速开始
1. git clone https://github.com/tangaiyun/redislimiter-spring-boot.git
2. cd redislimiter-spring-boot-starter
3. mvn clean install
4. 新建一个Spring boot API 项目,具体参考demo1项目,要在项目依赖中加入
<dependency>
<groupId>com.tay</groupId>
<artifactId>redislimiter-spring-boot-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
5. 修改项目resources/application.yml文件
server:
port: 8888 #端口
spring:
application:
name: demo1 #应用名称必须要配置,不然无法启动
redis-limiter: #限流器配置
redis-host: 127.0.0.1 #redis server ip
check-action-timeout: 100 #访问检查动作最大执行时间(单位毫秒)
enable-dynamical-conf: true #开启动态限流配置
spring.application.name必须配置
6. 新建一个RestController类
package com.tay.demo1;
import com.tay.redislimiter.RateLimiter;
import com.tay.redislimiter.dynamic.DynamicRateLimiter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

本文介绍了一个适用于微服务架构的分布式限流框架RedisLimiter-SpringBoot,通过详细步骤指导如何快速搭建并使用。涵盖了从项目克隆、安装到创建RESTController,以及配置详解,包括base、path、timeUnit、permits等属性的使用。同时,文章还介绍了动态配置限流规则的方法。
最低0.47元/天 解锁文章
1618

被折叠的 条评论
为什么被折叠?



