From 2e03dcba6946b4039fcd2b5b54c5f45106734918 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 10 Apr 2024 20:57:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20resilience4j=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 12 ---------- .../pom.xml | 6 ----- .../framework/resilience4j/package-info.java | 9 ------- ... Spring Boot 服务容错 Resilience4j 入门》.md | 1 - .../core/handler/GlobalExceptionHandler.java | 24 ++++--------------- .../test/resources/application-unit-test.yaml | 2 -- .../test/resources/application-unit-test.yaml | 2 -- .../test/resources/application-unit-test.yaml | 2 -- .../test/resources/application-unit-test.yaml | 2 -- .../test/resources/application-unit-test.yaml | 2 -- .../test/resources/application-unit-test.yaml | 2 -- .../test/resources/application-unit-test.yaml | 2 -- .../application-integration-test.yaml | 10 -------- .../test/resources/application-unit-test.yaml | 2 -- .../test/resources/application-unit-test.yaml | 2 -- .../application-integration-test.yaml | 10 -------- .../test/resources/application-unit-test.yaml | 2 -- .../src/main/resources/application-dev.yaml | 10 -------- .../src/main/resources/application-local.yaml | 10 -------- 19 files changed, 5 insertions(+), 107 deletions(-) delete mode 100644 yudao-framework/yudao-spring-boot-starter-protection/src/main/java/cn/iocoder/yudao/framework/resilience4j/package-info.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-protection/src/main/java/cn/iocoder/yudao/framework/resilience4j/《芋道 Spring Boot 服务容错 Resilience4j 入门》.md diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index f5a03a90b..09067a2a4 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -34,7 +34,6 @@ 2.2.3 2.2.7 - 2.1.0 9.0.0 3.2.1 @@ -282,17 +281,6 @@ - - io.github.resilience4j - resilience4j-ratelimiter - ${resilience4j.version} - - - io.github.resilience4j - resilience4j-spring-boot2 - ${resilience4j.version} - - cn.iocoder.boot diff --git a/yudao-framework/yudao-spring-boot-starter-protection/pom.xml b/yudao-framework/yudao-spring-boot-starter-protection/pom.xml index 46fd97e43..a93991ff5 100644 --- a/yudao-framework/yudao-spring-boot-starter-protection/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-protection/pom.xml @@ -35,12 +35,6 @@ lock4j-redisson-spring-boot-starter true - - - io.github.resilience4j - resilience4j-spring-boot2 - true - diff --git a/yudao-framework/yudao-spring-boot-starter-protection/src/main/java/cn/iocoder/yudao/framework/resilience4j/package-info.java b/yudao-framework/yudao-spring-boot-starter-protection/src/main/java/cn/iocoder/yudao/framework/resilience4j/package-info.java deleted file mode 100644 index 649e8a0ea..000000000 --- a/yudao-framework/yudao-spring-boot-starter-protection/src/main/java/cn/iocoder/yudao/framework/resilience4j/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * 使用 Resilience4j 组件,实现服务保障,包括: - * 1. 熔断器 - * 2. 限流器 - * 3. 舱壁隔离 - * 4. 重试 - * 5. 限时器 - */ -package cn.iocoder.yudao.framework.resilience4j; diff --git a/yudao-framework/yudao-spring-boot-starter-protection/src/main/java/cn/iocoder/yudao/framework/resilience4j/《芋道 Spring Boot 服务容错 Resilience4j 入门》.md b/yudao-framework/yudao-spring-boot-starter-protection/src/main/java/cn/iocoder/yudao/framework/resilience4j/《芋道 Spring Boot 服务容错 Resilience4j 入门》.md deleted file mode 100644 index 8d6d0335b..000000000 --- a/yudao-framework/yudao-spring-boot-starter-protection/src/main/java/cn/iocoder/yudao/framework/resilience4j/《芋道 Spring Boot 服务容错 Resilience4j 入门》.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java index 243f949f2..7c6014195 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java @@ -11,6 +11,10 @@ import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.ConstraintViolationException; +import jakarta.validation.ValidationException; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -26,13 +30,8 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.servlet.NoHandlerFoundException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.validation.ConstraintViolation; -import jakarta.validation.ConstraintViolationException; -import jakarta.validation.ValidationException; import java.time.LocalDateTime; import java.util.Map; -import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*; @@ -181,14 +180,6 @@ public class GlobalExceptionHandler { return CommonResult.error(METHOD_NOT_ALLOWED.getCode(), String.format("请求方法不正确:%s", ex.getMessage())); } - /** - * 处理 Resilience4j 限流抛出的异常 - */ - public CommonResult requestNotPermittedExceptionHandler(HttpServletRequest req, Throwable ex) { - log.warn("[requestNotPermittedExceptionHandler][url({}) 访问过于频繁]", req.getRequestURL(), ex); - return CommonResult.error(TOO_MANY_REQUESTS); - } - /** * 处理 Spring Security 权限不足的异常 * @@ -223,12 +214,7 @@ public class GlobalExceptionHandler { return tableNotExistsResult; } - // 情况二:部分特殊的库的处理 - if (Objects.equals("io.github.resilience4j.ratelimiter.RequestNotPermitted", ex.getClass().getName())) { - return requestNotPermittedExceptionHandler(req, ex); - } - - // 情况三:处理异常 + // 情况二:处理异常 log.error("[defaultExceptionHandler]", ex); // 插入异常日志 this.createExceptionLog(req, ex); diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/test/resources/application-unit-test.yaml b/yudao-module-bpm/yudao-module-bpm-biz/src/test/resources/application-unit-test.yaml index 1bbe0f530..dd9b95bfb 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/test/resources/application-unit-test.yaml @@ -32,8 +32,6 @@ mybatis-plus: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-crm/yudao-module-crm-biz/src/test/resources/application-unit-test.yaml b/yudao-module-crm/yudao-module-crm-biz/src/test/resources/application-unit-test.yaml index 0f28838da..a55b301c6 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-crm/yudao-module-crm-biz/src/test/resources/application-unit-test.yaml @@ -39,8 +39,6 @@ mybatis-plus: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/application-unit-test.yaml b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/application-unit-test.yaml index 2d0d827d2..d88a15a60 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/application-unit-test.yaml @@ -39,8 +39,6 @@ mybatis-plus: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/resources/application-unit-test.yaml b/yudao-module-mall/yudao-module-product-biz/src/test/resources/application-unit-test.yaml index 518fa712b..36aec5c43 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-mall/yudao-module-product-biz/src/test/resources/application-unit-test.yaml @@ -39,8 +39,6 @@ mybatis-plus: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/application-unit-test.yaml b/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/application-unit-test.yaml index 7b76570fd..f05f05074 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/resources/application-unit-test.yaml @@ -38,8 +38,6 @@ mybatis: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-unit-test.yaml b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-unit-test.yaml index 0aa14e897..4168a2bda 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-unit-test.yaml @@ -38,8 +38,6 @@ mybatis: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-member/yudao-module-member-biz/src/test/resources/application-unit-test.yaml b/yudao-module-member/yudao-module-member-biz/src/test/resources/application-unit-test.yaml index 7b76570fd..f05f05074 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-member/yudao-module-member-biz/src/test/resources/application-unit-test.yaml @@ -38,8 +38,6 @@ mybatis: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-pay/yudao-module-pay-biz/src/test-integration/resources/application-integration-test.yaml b/yudao-module-pay/yudao-module-pay-biz/src/test-integration/resources/application-integration-test.yaml index 0e55d5639..5a030df7b 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/test-integration/resources/application-integration-test.yaml +++ b/yudao-module-pay/yudao-module-pay-biz/src/test-integration/resources/application-integration-test.yaml @@ -71,16 +71,6 @@ mybatis-plus: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 -resilience4j: - ratelimiter: - instances: - backendA: - limit-for-period: 1 # 每个周期内,允许的请求数。默认为 50 - limit-refresh-period: 60s # 每个周期的时长,单位:微秒。默认为 500 - timeout-duration: 1s # 被限流时,阻塞等待的时长,单位:微秒。默认为 5s - register-health-indicator: true # 是否注册到健康监测 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-pay/yudao-module-pay-biz/src/test/resources/application-unit-test.yaml b/yudao-module-pay/yudao-module-pay-biz/src/test/resources/application-unit-test.yaml index 7b76570fd..f05f05074 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-pay/yudao-module-pay-biz/src/test/resources/application-unit-test.yaml @@ -38,8 +38,6 @@ mybatis: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-report/yudao-module-report-biz/src/test/resources/application-unit-test.yaml b/yudao-module-report/yudao-module-report-biz/src/test/resources/application-unit-test.yaml index 6bfd9953d..c0da26010 100644 --- a/yudao-module-report/yudao-module-report-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-report/yudao-module-report-biz/src/test/resources/application-unit-test.yaml @@ -38,8 +38,6 @@ mybatis: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-system/yudao-module-system-biz/src/test-integration/resources/application-integration-test.yaml b/yudao-module-system/yudao-module-system-biz/src/test-integration/resources/application-integration-test.yaml index 4a1880178..9b025ac8e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test-integration/resources/application-integration-test.yaml +++ b/yudao-module-system/yudao-module-system-biz/src/test-integration/resources/application-integration-test.yaml @@ -75,16 +75,6 @@ mybatis: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 -resilience4j: - ratelimiter: - instances: - backendA: - limit-for-period: 1 # 每个周期内,允许的请求数。默认为 50 - limit-refresh-period: 60s # 每个周期的时长,单位:微秒。默认为 500 - timeout-duration: 1s # 被限流时,阻塞等待的时长,单位:微秒。默认为 5s - register-health-indicator: true # 是否注册到健康监测 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-module-system/yudao-module-system-biz/src/test/resources/application-unit-test.yaml b/yudao-module-system/yudao-module-system-biz/src/test/resources/application-unit-test.yaml index 78d1d9c68..58bbf921b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-system/yudao-module-system-biz/src/test/resources/application-unit-test.yaml @@ -38,8 +38,6 @@ mybatis: # Lock4j 配置项(单元测试,禁用 Lock4j) -# Resilience4j 配置项 - --- #################### 监控相关配置 #################### --- #################### 芋道相关配置 #################### diff --git a/yudao-server/src/main/resources/application-dev.yaml b/yudao-server/src/main/resources/application-dev.yaml index 8caf15b08..c10cdcb45 100644 --- a/yudao-server/src/main/resources/application-dev.yaml +++ b/yudao-server/src/main/resources/application-dev.yaml @@ -115,16 +115,6 @@ 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/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 89a037830..555030b57 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -135,16 +135,6 @@ 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 监控端点的配置项