From 7c8bfa34435129577ce5cbadd984af9ac40094ac Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 24 Feb 2021 20:59:09 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E4=BF=9D=E9=9A=9C=E7=BB=84=E4=BB=B6=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=99=90=E6=B5=81=E3=80=81=E7=86=94=E6=96=AD=E7=AD=89=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=202.=20=E8=BF=9B=E4=B8=80=E6=AD=A5=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 32 +++++++++++++++++++ pom.xml | 7 ++++ ruoyi-ui/README.md | 30 ----------------- .../dashboard/DashboardApplication.java | 1 - .../enums/GlobalErrorCodeConstants.java | 3 +- .../《芋道 Spring Boot 异步任务入门》.md | 2 +- ...道 Spring Boot 多数据源(读写分离)入门》.md | 1 + .../《芋道 Spring Boot 数据库连接池入门》.md | 1 + .../core/DefaultLockFailureStrategy.java | 2 +- .../monitor/AdminServerConfiguration.java | 9 ++++++ .../framework/monitor/package-info.java | 4 +++ ...芋道 Spring Boot 监控工具 Admin 入门》.md | 1 + .../《芋道 Spring Boot MyBatis 入门》.md | 1 + .../《芋道 Spring Boot 定时任务入门》.md | 1 + .../framework/redis/package-info.java | 4 +++ .../redis/《芋道 Spring Boot Redis 入门》.md | 1 + .../framework/resilience4j/package-info.java | 9 ++++++ ...pring Boot 安全框架 Spring Security 入门》.md | 1 + ...pring Boot 安全框架 Spring Security 入门》.md | 4 +-- ... Spring Boot API 接口文档 Swagger 入门》.md | 2 +- ...道 Spring Boot 链路追踪 SkyWalking 入门》.md | 1 + .../framework/validator/package-info.java | 4 +++ ...道 Spring Boot 参数校验 Validation 入门》.md | 1 + .../core/handler/GlobalExceptionHandler.java | 13 ++++++++ .../《芋道 Spring Boot SpringMVC 入门》.md | 2 +- .../test/ToolTestDemoController.http | 6 +++- .../test/ToolTestDemoController.java | 2 ++ src/main/resources/application-dev.yaml | 10 ++++++ src/main/resources/application-local.yaml | 10 ++++++ 29 files changed, 126 insertions(+), 39 deletions(-) delete mode 100644 ruoyi-ui/README.md create mode 100644 src/main/java/cn/iocoder/dashboard/framework/datasource/《芋道 Spring Boot 多数据源(读写分离)入门》.md create mode 100644 src/main/java/cn/iocoder/dashboard/framework/datasource/《芋道 Spring Boot 数据库连接池入门》.md create mode 100644 src/main/java/cn/iocoder/dashboard/framework/monitor/AdminServerConfiguration.java create mode 100644 src/main/java/cn/iocoder/dashboard/framework/monitor/package-info.java create mode 100644 src/main/java/cn/iocoder/dashboard/framework/monitor/《芋道 Spring Boot 监控工具 Admin 入门》.md create mode 100644 src/main/java/cn/iocoder/dashboard/framework/mybatis/《芋道 Spring Boot MyBatis 入门》.md create mode 100644 src/main/java/cn/iocoder/dashboard/framework/quartz/《芋道 Spring Boot 定时任务入门》.md create mode 100644 src/main/java/cn/iocoder/dashboard/framework/redis/package-info.java create mode 100644 src/main/java/cn/iocoder/dashboard/framework/redis/《芋道 Spring Boot Redis 入门》.md create mode 100644 src/main/java/cn/iocoder/dashboard/framework/resilience4j/package-info.java create mode 100644 src/main/java/cn/iocoder/dashboard/framework/resilience4j/《芋道 Spring Boot 安全框架 Spring Security 入门》.md create mode 100644 src/main/java/cn/iocoder/dashboard/framework/tracer/《芋道 Spring Boot 链路追踪 SkyWalking 入门》.md create mode 100644 src/main/java/cn/iocoder/dashboard/framework/validator/package-info.java create mode 100644 src/main/java/cn/iocoder/dashboard/framework/validator/《芋道 Spring Boot 参数校验 Validation 入门》.md diff --git a/README.md b/README.md index d859b51a7..e039c6ead 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ 1. 链路追踪:基于 SkyWalking 实现性能监控,特别是链路的追踪 1. 分布式锁:基于 Redis 实现分布式锁,满足并发场景 1. 幂等组件:基于 Redis 实现幂等组件,解决重复请求问题 +1. 服务保障:基于 Resilience4j 实现服务的稳定性,包括限流、熔断等功能 ### 研发工具 @@ -58,6 +59,37 @@ > 未来会补充文档和视频,方便胖友冲冲冲! +## 技术栈 + +**后端** + +| 框架 | 说明 | 版本 | 学习指南 | +| --- | --- | --- | --- | +| [Spring Boot](https://spring.io/projects/spring-boot) | 应用开发框架 | 2.4.2 | [文档](https://github.com/YunaiV/SpringBoot-Labs) | +| [MySQL](https://www.mysql.com/cn/) | 数据库服务器 | 5.7 | | +| [Druid](https://github.com/alibaba/druid) | JDBC 连接池、监控组件 | 1.2.4 | [文档](http://www.iocoder.cn/Spring-Boot/datasource-pool/?yudao) | +| [MyBatis-Plus](https://mp.baomidou.com/) | MyBatis 增强工具包 | 3.4.1 | [文档](http://www.iocoder.cn/Spring-Boot/MyBatis/?yudao) | +| [Redis](https://redis.io/) | key-value 数据库 | 5.0 | | +| [Redisson](https://github.com/redisson/redisson) | Redis 客户端 | 3.1.46 | [文档](http://www.iocoder.cn/Spring-Boot/Redis/?yudao) | +| [Spring MVC](https://github.com/spring-projects/spring-framework/tree/master/spring-webmvc) | MVC 框架 | 5.4.2 | [文档](http://www.iocoder.cn/SpringMVC/MVC/?yudao) | +| [Spring Security](https://github.com/spring-projects/spring-security) | Spring 安全框架 | 5.4.2 | [文档](http://www.iocoder.cn/Spring-Boot/Spring-Security/?yudao) | +| [Hibernate Validator](https://github.com/hibernate/hibernate-validator) | 参数校验组件 | 6.1.7 | [文档](http://www.iocoder.cn/Spring-Boot/Validation/?yudao) | +| [Quartz](https://github.com/quartz-scheduler) | 任务调度组件 | 2.3.2 | [文档](http://www.iocoder.cn/Spring-Boot/Job/?yudao) | +| [Knife4j](https://gitee.com/xiaoym/knife4j) | Swagger 增强 UI 实现 | 3.0.2 | [文档](http://www.iocoder.cn/Spring-Boot/Swagger/?yudao) | +| [Resilience4j](https://github.com/quartz-scheduler) | 服务保障组件 | 1.7.0 | [文档](http://www.iocoder.cn/Spring-Boot/Resilience4j/?yudao) | +| [SkyWalking](https://skywalking.apache.org/) | 分布式应用追踪系统 | 8.6.0 | [文档](http://www.iocoder.cn/Spring-Boot/SkyWalking/?yudao) | +| [Spring Boot Admin](https://github.com/skywalking) | Spring Boot 监控平台 | 8.6.0 | [文档](http://www.iocoder.cn/Spring-Boot/Admin/?yudao) | +| [Jackson](https://github.com/FasterXML/jackson) | JSON 工具库 | 2.11.4 | | +| [MapStruct](https://mapstruct.org/) | Java Bean 转换 | 1.4.1 | [文档](http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao) | +| [Lombok](https://projectlombok.org/) | 消除冗长的 Java 代码| 1.16.14 | [文档](http://www.iocoder.cn/Spring-Boot/Lombok/?yudao) | + +**前端** + +| 框架 | 说明 | 版本 | +| --- | --- | --- | +| [Vue](https://cn.vuejs.org/index.html) | JavaScript 框架 | 2.6.12 | +| [Vue Element Admin](https://ant.design/docs/react/introduce-cn) | 后台前端解决方案 | - | + ## 演示图 diff --git a/pom.xml b/pom.xml index 09b8f70e3..1249edaf5 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,7 @@ 1.7.02.2.0 + 1.7.08.3.02.3.1 @@ -145,6 +146,12 @@ ${lock4j.version} + + io.github.resilience4j + resilience4j-spring-boot2 + ${resilience4j.version} + + org.apache.skywalking diff --git a/ruoyi-ui/README.md b/ruoyi-ui/README.md deleted file mode 100644 index e8e6b3407..000000000 --- a/ruoyi-ui/README.md +++ /dev/null @@ -1,30 +0,0 @@ -## 开发 - -```bash -# 克隆项目 -git clone https://github.com/YunaiV/ruoyi-vue-pro - -# 进入项目目录 -cd ruoyi-ui - -# 安装依赖 -npm install - -# 建议不要直接使用 cnpm 安装依赖,会有各种诡异的 bug。可以通过如下操作解决 npm 下载速度慢的问题 -npm install --registry=https://registry.npm.taobao.org - -# 启动服务 -npm run dev -``` - -浏览器访问 http://localhost:80 - -## 发布 - -```bash -# 构建测试环境 -npm run build:stage - -# 构建生产环境 -npm run build:prod -``` diff --git a/src/main/java/cn/iocoder/dashboard/DashboardApplication.java b/src/main/java/cn/iocoder/dashboard/DashboardApplication.java index a0a95f0ef..b54744c2b 100644 --- a/src/main/java/cn/iocoder/dashboard/DashboardApplication.java +++ b/src/main/java/cn/iocoder/dashboard/DashboardApplication.java @@ -5,7 +5,6 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -@EnableAdminServer // TODO 芋艿:需要迁移出去 public class DashboardApplication { public static void main(String[] args) { diff --git a/src/main/java/cn/iocoder/dashboard/common/exception/enums/GlobalErrorCodeConstants.java b/src/main/java/cn/iocoder/dashboard/common/exception/enums/GlobalErrorCodeConstants.java index d08121242..146de8078 100644 --- a/src/main/java/cn/iocoder/dashboard/common/exception/enums/GlobalErrorCodeConstants.java +++ b/src/main/java/cn/iocoder/dashboard/common/exception/enums/GlobalErrorCodeConstants.java @@ -23,6 +23,8 @@ public interface GlobalErrorCodeConstants { ErrorCode FORBIDDEN = new ErrorCode(403, "没有该操作权限"); ErrorCode NOT_FOUND = new ErrorCode(404, "请求未找到"); ErrorCode METHOD_NOT_ALLOWED = new ErrorCode(405, "请求方法不正确"); + ErrorCode LOCKED = new ErrorCode(423, "请求失败,请稍后重试"); // 并发请求,不允许 + ErrorCode TOO_MANY_REQUESTS = new ErrorCode(429, "请求过于频繁,请稍后重试"); // ========== 服务端错误段 ========== @@ -30,7 +32,6 @@ public interface GlobalErrorCodeConstants { // ========== 自定义错误段 ========== ErrorCode REPEATED_REQUESTS = new ErrorCode(900, "重复请求,请稍后重试"); // 重复请求 - ErrorCode CONCURRENCY_REQUESTS = new ErrorCode(901, "请求失败,请稍后重试"); // 并发请求,不允许 ErrorCode UNKNOWN = new ErrorCode(999, "未知错误"); diff --git a/src/main/java/cn/iocoder/dashboard/framework/async/《芋道 Spring Boot 异步任务入门》.md b/src/main/java/cn/iocoder/dashboard/framework/async/《芋道 Spring Boot 异步任务入门》.md index b2ef210bd..5822b838c 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/async/《芋道 Spring Boot 异步任务入门》.md +++ b/src/main/java/cn/iocoder/dashboard/framework/async/《芋道 Spring Boot 异步任务入门》.md @@ -1 +1 @@ - + diff --git a/src/main/java/cn/iocoder/dashboard/framework/datasource/《芋道 Spring Boot 多数据源(读写分离)入门》.md b/src/main/java/cn/iocoder/dashboard/framework/datasource/《芋道 Spring Boot 多数据源(读写分离)入门》.md new file mode 100644 index 000000000..21133741e --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/datasource/《芋道 Spring Boot 多数据源(读写分离)入门》.md @@ -0,0 +1 @@ + diff --git a/src/main/java/cn/iocoder/dashboard/framework/datasource/《芋道 Spring Boot 数据库连接池入门》.md b/src/main/java/cn/iocoder/dashboard/framework/datasource/《芋道 Spring Boot 数据库连接池入门》.md new file mode 100644 index 000000000..21b5075d5 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/datasource/《芋道 Spring Boot 数据库连接池入门》.md @@ -0,0 +1 @@ + diff --git a/src/main/java/cn/iocoder/dashboard/framework/lock4j/core/DefaultLockFailureStrategy.java b/src/main/java/cn/iocoder/dashboard/framework/lock4j/core/DefaultLockFailureStrategy.java index 7f1b19cb4..066cbf9fd 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/lock4j/core/DefaultLockFailureStrategy.java +++ b/src/main/java/cn/iocoder/dashboard/framework/lock4j/core/DefaultLockFailureStrategy.java @@ -14,7 +14,7 @@ public class DefaultLockFailureStrategy implements LockFailureStrategy { @Override public void onLockFailure(String key, long acquireTimeout, int acquireCount) { log.debug("[onLockFailure][线程:{} 获取锁失败,key:{} 获取超时时长:{} ms]", Thread.currentThread().getName(), key, acquireTimeout); - throw new ServiceException(GlobalErrorCodeConstants.CONCURRENCY_REQUESTS); + throw new ServiceException(GlobalErrorCodeConstants.LOCKED); } } diff --git a/src/main/java/cn/iocoder/dashboard/framework/monitor/AdminServerConfiguration.java b/src/main/java/cn/iocoder/dashboard/framework/monitor/AdminServerConfiguration.java new file mode 100644 index 000000000..30e5e23c4 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/monitor/AdminServerConfiguration.java @@ -0,0 +1,9 @@ +package cn.iocoder.dashboard.framework.monitor; + +import de.codecentric.boot.admin.server.config.EnableAdminServer; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableAdminServer +public class AdminServerConfiguration { +} diff --git a/src/main/java/cn/iocoder/dashboard/framework/monitor/package-info.java b/src/main/java/cn/iocoder/dashboard/framework/monitor/package-info.java new file mode 100644 index 000000000..dec6e31fb --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/monitor/package-info.java @@ -0,0 +1,4 @@ +/** + * 使用 Spring Boot Admin 实现简单的监控平台 + */ +package cn.iocoder.dashboard.framework.monitor; diff --git a/src/main/java/cn/iocoder/dashboard/framework/monitor/《芋道 Spring Boot 监控工具 Admin 入门》.md b/src/main/java/cn/iocoder/dashboard/framework/monitor/《芋道 Spring Boot 监控工具 Admin 入门》.md new file mode 100644 index 000000000..a1e367684 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/monitor/《芋道 Spring Boot 监控工具 Admin 入门》.md @@ -0,0 +1 @@ + diff --git a/src/main/java/cn/iocoder/dashboard/framework/mybatis/《芋道 Spring Boot MyBatis 入门》.md b/src/main/java/cn/iocoder/dashboard/framework/mybatis/《芋道 Spring Boot MyBatis 入门》.md new file mode 100644 index 000000000..d684e1dd6 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/mybatis/《芋道 Spring Boot MyBatis 入门》.md @@ -0,0 +1 @@ + diff --git a/src/main/java/cn/iocoder/dashboard/framework/quartz/《芋道 Spring Boot 定时任务入门》.md b/src/main/java/cn/iocoder/dashboard/framework/quartz/《芋道 Spring Boot 定时任务入门》.md new file mode 100644 index 000000000..65647011c --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/quartz/《芋道 Spring Boot 定时任务入门》.md @@ -0,0 +1 @@ + diff --git a/src/main/java/cn/iocoder/dashboard/framework/redis/package-info.java b/src/main/java/cn/iocoder/dashboard/framework/redis/package-info.java new file mode 100644 index 000000000..8d1562ad0 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/redis/package-info.java @@ -0,0 +1,4 @@ +/** + * 采用 Spring Data Redis 操作 Redis,底层使用 Redisson 作为客户端 + */ +package cn.iocoder.dashboard.framework.redis; diff --git a/src/main/java/cn/iocoder/dashboard/framework/redis/《芋道 Spring Boot Redis 入门》.md b/src/main/java/cn/iocoder/dashboard/framework/redis/《芋道 Spring Boot Redis 入门》.md new file mode 100644 index 000000000..80c544590 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/redis/《芋道 Spring Boot Redis 入门》.md @@ -0,0 +1 @@ + diff --git a/src/main/java/cn/iocoder/dashboard/framework/resilience4j/package-info.java b/src/main/java/cn/iocoder/dashboard/framework/resilience4j/package-info.java new file mode 100644 index 000000000..8fb776083 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/resilience4j/package-info.java @@ -0,0 +1,9 @@ +/** + * 使用 Resilience4j 组件,实现服务保障,包括: + * 1. 熔断器 + * 2. 限流器 + * 3. 舱壁隔离 + * 4. 重试 + * 5. 限时器 + */ +package cn.iocoder.dashboard.framework.resilience4j; diff --git a/src/main/java/cn/iocoder/dashboard/framework/resilience4j/《芋道 Spring Boot 安全框架 Spring Security 入门》.md b/src/main/java/cn/iocoder/dashboard/framework/resilience4j/《芋道 Spring Boot 安全框架 Spring Security 入门》.md new file mode 100644 index 000000000..3fa673793 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/resilience4j/《芋道 Spring Boot 安全框架 Spring Security 入门》.md @@ -0,0 +1 @@ + diff --git a/src/main/java/cn/iocoder/dashboard/framework/security/《芋道 Spring Boot 安全框架 Spring Security 入门》.md b/src/main/java/cn/iocoder/dashboard/framework/security/《芋道 Spring Boot 安全框架 Spring Security 入门》.md index dddf73635..b8a89316f 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/security/《芋道 Spring Boot 安全框架 Spring Security 入门》.md +++ b/src/main/java/cn/iocoder/dashboard/framework/security/《芋道 Spring Boot 安全框架 Spring Security 入门》.md @@ -1,2 +1,2 @@ -* 芋道 Spring Security 入门: -* Spring Security 基本概念: +* 芋道 Spring Security 入门: +* Spring Security 基本概念: diff --git a/src/main/java/cn/iocoder/dashboard/framework/swagger/《芋道 Spring Boot API 接口文档 Swagger 入门》.md b/src/main/java/cn/iocoder/dashboard/framework/swagger/《芋道 Spring Boot API 接口文档 Swagger 入门》.md index 906a67200..7ed5ebd1b 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/swagger/《芋道 Spring Boot API 接口文档 Swagger 入门》.md +++ b/src/main/java/cn/iocoder/dashboard/framework/swagger/《芋道 Spring Boot API 接口文档 Swagger 入门》.md @@ -1 +1 @@ - + diff --git a/src/main/java/cn/iocoder/dashboard/framework/tracer/《芋道 Spring Boot 链路追踪 SkyWalking 入门》.md b/src/main/java/cn/iocoder/dashboard/framework/tracer/《芋道 Spring Boot 链路追踪 SkyWalking 入门》.md new file mode 100644 index 000000000..ed9d4fe47 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/tracer/《芋道 Spring Boot 链路追踪 SkyWalking 入门》.md @@ -0,0 +1 @@ + diff --git a/src/main/java/cn/iocoder/dashboard/framework/validator/package-info.java b/src/main/java/cn/iocoder/dashboard/framework/validator/package-info.java new file mode 100644 index 000000000..e6a861e5c --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/validator/package-info.java @@ -0,0 +1,4 @@ +/** + * 使用 Hibernate Validator 实现参数校验 + */ +package cn.iocoder.dashboard.framework.validator; diff --git a/src/main/java/cn/iocoder/dashboard/framework/validator/《芋道 Spring Boot 参数校验 Validation 入门》.md b/src/main/java/cn/iocoder/dashboard/framework/validator/《芋道 Spring Boot 参数校验 Validation 入门》.md new file mode 100644 index 000000000..b2c2cf8f5 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/validator/《芋道 Spring Boot 参数校验 Validation 入门》.md @@ -0,0 +1 @@ + diff --git a/src/main/java/cn/iocoder/dashboard/framework/web/core/handler/GlobalExceptionHandler.java b/src/main/java/cn/iocoder/dashboard/framework/web/core/handler/GlobalExceptionHandler.java index c0974a0f0..5f2748dfd 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/web/core/handler/GlobalExceptionHandler.java +++ b/src/main/java/cn/iocoder/dashboard/framework/web/core/handler/GlobalExceptionHandler.java @@ -4,6 +4,7 @@ import cn.iocoder.dashboard.common.exception.GlobalException; import cn.iocoder.dashboard.common.exception.ServiceException; import cn.iocoder.dashboard.common.pojo.CommonResult; import cn.iocoder.dashboard.framework.security.core.util.SecurityUtils; +import io.github.resilience4j.ratelimiter.RequestNotPermitted; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.AccessDeniedException; import org.springframework.validation.BindException; @@ -63,6 +64,9 @@ public class GlobalExceptionHandler { if (ex instanceof HttpRequestMethodNotSupportedException) { return httpRequestMethodNotSupportedExceptionHandler((HttpRequestMethodNotSupportedException) ex); } + if (ex instanceof RequestNotPermitted) { + return requestNotPermittedExceptionHandler(request, (RequestNotPermitted) ex); + } if (ex instanceof ServiceException) { return serviceExceptionHandler((ServiceException) ex); } @@ -163,6 +167,15 @@ public class GlobalExceptionHandler { return CommonResult.error(METHOD_NOT_ALLOWED.getCode(), String.format("请求方法不正确:%s", ex.getMessage())); } + /** + * 处理 Resilience4j 限流抛出的异常 + */ + @ExceptionHandler(value = RequestNotPermitted.class) + public CommonResult requestNotPermittedExceptionHandler(HttpServletRequest req, RequestNotPermitted ex) { + log.warn("[requestNotPermittedExceptionHandler][url({}) 访问过于频繁]", req.getRequestURL(), ex); + return CommonResult.error(TOO_MANY_REQUESTS); + } + /** * 处理 Spring Security 权限不足的异常 * diff --git a/src/main/java/cn/iocoder/dashboard/framework/web/《芋道 Spring Boot SpringMVC 入门》.md b/src/main/java/cn/iocoder/dashboard/framework/web/《芋道 Spring Boot SpringMVC 入门》.md index 82c1fe55f..7c36a1591 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/web/《芋道 Spring Boot SpringMVC 入门》.md +++ b/src/main/java/cn/iocoder/dashboard/framework/web/《芋道 Spring Boot SpringMVC 入门》.md @@ -1 +1 @@ - + diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/controller/test/ToolTestDemoController.http b/src/main/java/cn/iocoder/dashboard/modules/tool/controller/test/ToolTestDemoController.http index b9d9fea9b..b10a3d293 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/controller/test/ToolTestDemoController.http +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/controller/test/ToolTestDemoController.http @@ -1,3 +1,7 @@ -### 请求 /get-permission-info 接口 => 成功 +### 请求 /tool/test-demo/get 接口 => 成功 GET {{baseUrl}}/tool/test-demo/get?id=1 Authorization: Bearer {{token}} + +### 请求 /tool/test-demo/list 接口 => 成功 +GET {{baseUrl}}/tool/test-demo/list?ids=1 +Authorization: Bearer {{token}} diff --git a/src/main/java/cn/iocoder/dashboard/modules/tool/controller/test/ToolTestDemoController.java b/src/main/java/cn/iocoder/dashboard/modules/tool/controller/test/ToolTestDemoController.java index e89b35f90..13f70ec0d 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/tool/controller/test/ToolTestDemoController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/tool/controller/test/ToolTestDemoController.java @@ -10,6 +10,7 @@ import cn.iocoder.dashboard.modules.tool.convert.test.ToolTestDemoConvert; import cn.iocoder.dashboard.modules.tool.dal.dataobject.test.ToolTestDemoDO; import cn.iocoder.dashboard.modules.tool.service.test.ToolTestDemoService; import com.baomidou.lock.annotation.Lock4j; +import io.github.resilience4j.ratelimiter.annotation.RateLimiter; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -78,6 +79,7 @@ public class ToolTestDemoController { @ApiOperation("获得测试示例列表") @ApiImplicitParam(name = "ids", value = "编号列表", required = true, dataTypeClass = List.class) @PreAuthorize("@ss.hasPermission('tool:test-demo:query')") + @RateLimiter(name = "backendA") public CommonResult> getTestDemoList(@RequestParam("ids") Collection ids) { List list = testDemoService.getTestDemoList(ids); return success(ToolTestDemoConvert.INSTANCE.convertList(list)); diff --git a/src/main/resources/application-dev.yaml b/src/main/resources/application-dev.yaml index 08209bfa9..01349ef49 100644 --- a/src/main/resources/application-dev.yaml +++ b/src/main/resources/application-dev.yaml @@ -88,6 +88,16 @@ lock4j: acquire-timeout: 3000 # 获取分布式锁超时时间,默认为 3000 毫秒 expire: 30000 # 分布式锁的超时时间,默认为 30 毫秒 +# Resilience4j 配置项 +resilience4j: + ratelimiter: + instances: + backendA: + limit-for-period: 1 # 每个周期内,允许的请求数。默认为 50 + limit-refresh-period: 60s # 每个周期的时长,单位:微秒。默认为 500 + timeout-duration: 1s # 被限流时,阻塞等待的时长,单位:微秒。默认为 5s + register-health-indicator: true # 是否注册到健康监测 + --- #################### 监控相关配置 #################### # Actuator 监控端点的配置项 diff --git a/src/main/resources/application-local.yaml b/src/main/resources/application-local.yaml index 6a5b2995b..5dc75f500 100644 --- a/src/main/resources/application-local.yaml +++ b/src/main/resources/application-local.yaml @@ -88,6 +88,16 @@ lock4j: acquire-timeout: 3000 # 获取分布式锁超时时间,默认为 3000 毫秒 expire: 30000 # 分布式锁的超时时间,默认为 30 毫秒 +# Resilience4j 配置项 +resilience4j: + ratelimiter: + instances: + backendA: + limit-for-period: 1 # 每个周期内,允许的请求数。默认为 50 + limit-refresh-period: 60s # 每个周期的时长,单位:微秒。默认为 500 + timeout-duration: 1s # 被限流时,阻塞等待的时长,单位:微秒。默认为 5s + register-health-indicator: true # 是否注册到健康监测 + --- #################### 监控相关配置 #################### # Actuator 监控端点的配置项