From dcc110c3e3311b1c82c6441a9c42b71ada9ae079 Mon Sep 17 00:00:00 2001
From: byteblogs168 <598092184@qq.com>
Date: Sun, 3 Sep 2023 23:49:11 +0800
Subject: [PATCH 1/7] =?UTF-8?q?=E5=AE=8C=E6=88=90swagger3.x=E7=89=88?=
=?UTF-8?q?=E6=9C=AC=E6=8E=A5=E5=85=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 15 +-
.../easy/retry/config/SwaggerConfig.java | 54 +++---
.../LocalAndRemoteRetryController.java | 29 ++--
.../controller/LocalRetryController.java | 73 +++++----
.../ManualRetryExecutorController.java | 27 +--
.../controller/RemoteRetryController.java | 155 +++++++++---------
.../com/example/easy/retry/vo/OrderVo.java | 7 +-
7 files changed, 188 insertions(+), 172 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9b4489f..c65eb97 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.6.8
+ 3.1.3
@@ -16,7 +16,7 @@
Demo project for Spring Boot
- 1.8
+ 17
@@ -68,7 +68,7 @@
com.baomidou
mybatis-plus-boot-starter
- 3.5.1
+ 3.5.3.2
com.baomidou
@@ -79,7 +79,6 @@
org.freemarker
freemarker
2.3.28
- compile
cn.hutool
@@ -91,13 +90,11 @@
mysql-connector-java
8.0.30
-
- io.springfox
- springfox-boot-starter
- 3.0.0
+ org.springdoc
+ springdoc-openapi-starter-webmvc-ui
+ 2.2.0
-
com.alibaba
transmittable-thread-local
diff --git a/src/main/java/com/example/easy/retry/config/SwaggerConfig.java b/src/main/java/com/example/easy/retry/config/SwaggerConfig.java
index 025509a..3cd0074 100644
--- a/src/main/java/com/example/easy/retry/config/SwaggerConfig.java
+++ b/src/main/java/com/example/easy/retry/config/SwaggerConfig.java
@@ -1,15 +1,14 @@
package com.example.easy.retry.config;
import com.aizuda.easy.retry.common.core.util.EasyRetryVersion;
+import io.swagger.v3.oas.models.ExternalDocumentation;
+import io.swagger.v3.oas.models.OpenAPI;
+import io.swagger.v3.oas.models.info.Info;
+import io.swagger.v3.oas.models.info.License;
+import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import springfox.documentation.builders.ApiInfoBuilder;
-import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.service.ApiInfo;
-import springfox.documentation.spi.DocumentationType;
-import springfox.documentation.spring.web.plugins.Docket;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
/**
* @author: www.byteblogs.com
@@ -17,31 +16,34 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
* @since 2.1.0
*/
@Configuration
-@EnableSwagger2
public class SwaggerConfig {
- @Bean
- public Docket api() {
- return new Docket(DocumentationType.SWAGGER_2)
- .select()
- .apis(RequestHandlerSelectors.basePackage("com.example.easy.retry.controller")) // 替换为你的项目包名
- .paths(PathSelectors.any())
- .build()
- .apiInfo(apiInfo());
- }
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- .title("Easy Retry Example")
- .description(
- "EasyRetry是致力提高分布式业务系统一致性的分布式重试平台
\n" +
+ @Bean
+ public OpenAPI springShopOpenAPI() {
+ return new OpenAPI()
+ .info(new Info()
+ .title("Easy Retry Example")
+ .description("EasyRetry是致力提高分布式业务系统一致性的分布式重试平台
\n" +
"官网地址: https://www.easyretry.com/
" +
"在线体验地址: http://preview.easyretry.com/
" +
"源码地址: https://gitee.com/byteblogs168/easy-retry-demo
" +
- "视频教程: 🌻https://www.ixigua.com/pseries/7272009348824433213/.
" +
- "特别提醒: 🌻在您使用测试案例之前请认真的阅读官网.
"
+ "特别提醒: 🌻在您使用测试案例之前请认真的阅读官网.
")
+ .version(EasyRetryVersion.getVersion())
+ .license(new License().name("Apache 2.0").url("https://www.easyretry.com/")))
+ .externalDocs(new ExternalDocumentation()
+ .description("视频教程:从0到1快速了解分布式重试组件EasyRetry")
+ .url("https://www.ixigua.com/pseries/7272009348824433213/"))
+ ;
+ }
- )
- .version(EasyRetryVersion.getVersion())
+ @Bean
+ public GroupedOpenApi adminApi() {
+ return GroupedOpenApi.builder()
+ //分组名
+ .group("user")
+ .pathsToMatch("/**")
+ //扫描路径,将路径下有swagger注解的接口解析到文档中
+ .packagesToScan("com.example.easy.retry.controller")
.build();
}
}
diff --git a/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java b/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java
index cb19b65..b41bad6 100644
--- a/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java
@@ -1,9 +1,10 @@
package com.example.easy.retry.controller;
-import com.example.easy.retry.service.impl.LocalRemoteServiceImpl;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
+import com.example.easy.retry.service.LocalRemoteService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -12,28 +13,30 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/local-remote")
-@Api(value = "模拟先本地再远程重试案例", tags = "先本地再远程重试案例【RetryType.LOCAL_REMOTE】")
+@Tag(name = "模拟先本地再远程重试案例", description = "先本地再远程重试案例【RetryType.LOCAL_REMOTE】")
public class LocalAndRemoteRetryController {
@Autowired
- private LocalRemoteServiceImpl localRemoteServiceImpl;
+ private LocalRemoteService localRemoteService;
@GetMapping("/retry")
- @ApiOperation(value = "一个简单的入门案例")
+ @Operation(description = "一个简单的入门案例")
public void localRemote() {
- localRemoteServiceImpl.localRemote();
+ localRemoteService.localRemote();
}
@GetMapping("/retryWithLocalRemote")
- @ApiOperation(
- value = "使用同步上报的方式",
- notes = "async = false 代表使用同步上传的方式\n"
+ @Operation(
+ summary = "使用同步上报的方式",
+ description = "async = false 代表使用同步上传的方式\n"
+ "timeout = 1 代表超时时间为1 \n"
+ "unit = MINUTES 代表超时时间的单位是分钟\n" +
"📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
- public void remoteRetryWithLocalRemote(@ApiParam(name = "params", value = "测试参数", defaultValue = "test")
+ public void remoteRetryWithLocalRemote(@Parameter(name = "params", description = "测试参数",
+ schema = @Schema(type = "String", description = "测试参数", defaultValue = "test")
+ )
@RequestParam("params") String params) {
- localRemoteServiceImpl.remoteRetryWithLocalRemote(params);
+ localRemoteService.remoteRetryWithLocalRemote(params);
}
}
diff --git a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
index 8f91140..8266ae8 100644
--- a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
@@ -1,28 +1,35 @@
package com.example.easy.retry.controller;
-import com.example.easy.retry.service.LocalRetryService;
-import com.example.easy.retry.vo.OrderVo;
-import io.swagger.annotations.*;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.enums.ParameterIn;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
-import com.example.easy.retry.service.impl.LocalRetryServiceImpl;
+import com.example.easy.retry.service.LocalRetryService;
@RestController
@RequestMapping("/local")
-@Api(value = "模拟本地重试", tags = "本地重试案例 【RetryType.ONLY_LOCAL】")
+@Tag(name = "模拟本地重试", description = "本地重试案例 【RetryType.ONLY_LOCAL】")
public class LocalRetryController {
@Autowired
private LocalRetryService localRetryService;
@GetMapping("/retry")
- @ApiOperation(
- value = "一个简单的入门案例",
- notes = "🥇仅仅在本地进行内存重试\n" +
+ @Operation(
+ summary = "一个简单的入门案例",
+ description = "🥇仅仅在本地进行内存重试\n" +
"📢任务列表: http://preview.easyretry.com/#/retry-task/list"
)
- public void onlyLocalRetry(@ApiParam(name = "params", value = "测试参数", defaultValue = "test") @RequestParam("params") String params){
+ public void onlyLocalRetry(@Param(value = "测试参数") @RequestParam("params") String params) {
localRetryService.localRetry(params);
}
@@ -35,59 +42,55 @@ public class LocalRetryController {
}
@GetMapping("/withBasicParams")
- @ApiOperation(
- value = "指定基础参数",
- notes = "localTimes 本地重试次数\n" +
+ @Operation(
+ summary = "指定基础参数",
+ description = "localTimes 本地重试次数\n" +
"localInterval 本地重试间隔时间(默认单位为秒)\n" +
"unit 超时时间单位\n" +
"本案例设置为本地重试4次,每次重试之间间隔10s"
)
- public void localRetryWithBasicParams(@ApiParam(name = "params", value = "测试参数", defaultValue = "test") @RequestParam("params") String params){
+ public void localRetryWithBasicParams(@Parameter(name = "params") String params) {
localRetryService.localRetryWithBasicParams(params);
}
@GetMapping("/includeException")
- @ApiOperation(
- value = "指定异常参数",
- notes = "include参数指的是当我们遭遇到指定异常时进行重试\n" +
+ @Operation(
+ summary = "指定异常参数",
+ description = "include参数指的是当我们遭遇到指定异常时进行重试\n" +
"在这个案例中我们处理两个场景:\n" +
"抛出指定异常,例如抛出自定义的ParamException异常,观察是否会重试\n" +
"抛出非指定异常,例如我们在这里产生一个异常,观察是否会重试\n" +
"注意:如果此时我们在include 中指定参数为BusinessException(ParamException的父类),同样也会进行重试逻辑\n" +
"下面参数可以指定:NullPointerException, ParamException"
)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "type", value = "异常类型", dataType = "String", paramType = "query",
- allowableValues = "NullPointerException,ParamException", defaultValue = "ParamException")
- })
- public void localRetryIncludeException(@RequestParam("type") String type){
+ public void localRetryIncludeException(@Parameter(name = "type", description = "异常类型", in = ParameterIn.QUERY,
+ schema = @Schema(type = "String", description = "异常类型")) @RequestParam("type") String type) {
localRetryService.localRetryIncludeException(type);
}
@GetMapping("/excludeException")
- @ApiOperation(
- value = "非指定异常参数进行重试",
- notes = "这个参数的作用和include是相反的\n" +
+ @Operation(
+ summary = "非指定异常参数进行重试",
+ description = "这个参数的作用和include是相反的\n" +
"exclude参数指的是当我们遇到指定异常时则不会进行重试\n" +
"比如在下述案例中我们指定了遇到ParamException和ArithmeticException后不进行重试"
)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "type", value = "异常类型", dataType = "String", paramType = "query",
- allowableValues = "ParamException,ArithmeticException", defaultValue = "ParamException")
+ @Parameters({
+ @Parameter(name = "type", description = "异常类型", in = ParameterIn.QUERY)
})
- public void localRetryExcludeException(@RequestParam("type") String type){
+ public void localRetryExcludeException(@RequestParam("type") String type) {
localRetryService.localRetryExcludeException(type);
}
@GetMapping("/isThrowException")
- @ApiOperation(
- value = "本地重试完成后不抛出异常",
- notes = ""
+ @Operation(
+ summary = "本地重试完成后不抛出异常",
+ description = ""
)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "params", value = "异常类型", dataType = "String", paramType = "query")
+ @Parameters({
+ @Parameter(name = "params", description = "异常类型", in = ParameterIn.QUERY)
})
- public void localRetryIsThrowException(@RequestParam("params") String params){
+ public void localRetryIsThrowException(@RequestParam("params") String params) {
localRetryService.localRetryIsThrowException(params);
}
diff --git a/src/main/java/com/example/easy/retry/controller/ManualRetryExecutorController.java b/src/main/java/com/example/easy/retry/controller/ManualRetryExecutorController.java
index eb44a51..302ecef 100644
--- a/src/main/java/com/example/easy/retry/controller/ManualRetryExecutorController.java
+++ b/src/main/java/com/example/easy/retry/controller/ManualRetryExecutorController.java
@@ -1,30 +1,33 @@
package com.example.easy.retry.controller;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
-import com.example.easy.retry.service.impl.ManualRetryExecutorMethodServiceImpl;
+import com.example.easy.retry.service.ManualRetryExecutorMethodService;
@RestController
@RequestMapping("/manual")
-@Api(value = "模拟手动执行重试案例", tags = "手动执行重试上报")
+@Tag(name = "模拟手动执行重试案例", description = "手动执行重试上报")
public class ManualRetryExecutorController {
@Autowired
- private ManualRetryExecutorMethodServiceImpl manualRetryExecutorMethodServiceImpl;
- @ApiOperation(
- value = "手动重试",
- notes = "❤️如果不知道这个手动重试的使用场景可以参考: https://www.easyretry.com/pages/406a68/#%E5%8F%91%E9%80%81mq%E5%9C%BA%E6%99%AF \n"
- + "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
+ private ManualRetryExecutorMethodService manualRetryExecutorMethodService;
+
+ @Operation(
+ summary = "手动重试",
+ description = "❤️如果不知道这个手动重试的使用场景可以参考: https://www.easyretry.com/pages/406a68/#%E5%8F%91%E9%80%81mq%E5%9C%BA%E6%99%AF \n"
+ + "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
@GetMapping("/retry")
- public void remoteRetryWithCallback(@ApiParam(name = "params", value = "测试参数", defaultValue = "test") @RequestParam("params") String params){
- manualRetryExecutorMethodServiceImpl.myExecutorMethod(params);
+ public void remoteRetryWithCallback(@Parameter(name = "params", description = "测试参数", schema = @Schema(description = "测试参数", defaultValue = "test"))
+ @RequestParam("params") String params) {
+ manualRetryExecutorMethodService.myExecutorMethod(params);
}
}
diff --git a/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java b/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
index d2ab539..0ab0d54 100644
--- a/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
@@ -1,105 +1,112 @@
package com.example.easy.retry.controller;
-
import java.util.Random;
import java.util.UUID;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
import com.example.easy.retry.vo.OrderVo;
-import com.example.easy.retry.service.impl.RemoteRetryServiceImpl;
+import com.example.easy.retry.service.RemoteRetryService;
@RestController
@RequestMapping("/remote")
-@Api(value = "模拟远程重试案例", tags = "远程重试案例【RetryType.ONLY_REMOTE】")
+@Tag(name = "模拟远程重试案例", description = "远程重试案例【RetryType.ONLY_REMOTE】")
public class RemoteRetryController {
@Autowired
- private RemoteRetryServiceImpl remoteRetryServiceImpl;
+ private RemoteRetryService remoteRetryService;
/**
* 一个最简单的远程调用案例
*/
@GetMapping("/retry")
- @ApiOperation(
- value = "一个简单的入门案例",
- notes = "🥇不进过本地重试阶段,直接上报到服务端\n" +
- "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
+ @Operation(
+ summary = "一个简单的入门案例",
+ description = "🥇不进过本地重试阶段,直接上报到服务端\n" +
+ "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
- public void remote(@ApiParam(name = "params", value = "测试参数", defaultValue = "test")
- @RequestParam("params") String params) {
- remoteRetryServiceImpl.remoteRetry(params);
+ public void remote(@Parameter(name = "params", description = "测试参数",
+ schema = @Schema(defaultValue = "test", type = "String", description = "测试参数"))
+ @RequestParam("params") String params) {
+ remoteRetryService.remoteRetry(params);
}
/**
* 一个最简单的远程调用案例
*/
@GetMapping("/retry/sync")
- @ApiOperation(
- value = "一个简单的以同步方式远程重试入门案例",
- notes = "🥇不进过本地重试阶段,直接上报到服务端\n" +
+ @Operation(
+ summary = "一个简单的以同步方式远程重试入门案例",
+ description = "🥇不进过本地重试阶段,直接上报到服务端\n" +
"📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
- public void remoteSync(@ApiParam(name = "params", value = "测试参数", defaultValue = "test")
- @RequestParam("params") String params) {
- remoteRetryServiceImpl.remoteSync(params);
+ public void remoteSync(@Parameter(name = "params", description = "测试参数",
+ schema = @Schema(type = "String", defaultValue = "test", description = "测试参数"))
+ @RequestParam("params") String params) {
+ remoteRetryService.remoteSync(params);
}
/**
* 使用自定义的幂等Id生成规则
*/
@PostMapping("/retryWithIdempotentId")
- @ApiOperation(
- value = "使用自定义的幂等Id生成规则",
- notes =
- "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/OrderIdempotentIdGenerate.java\n"
- + "具体的幂等策略参考: https://www.easyretry.com/pages/97cde9/#%E2%9A%A1%E5%B9%82%E7%AD%89id-idempotentid \n"
- +
- "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
+ @Operation(
+ summary = "使用自定义的幂等Id生成规则",
+ description =
+ "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/OrderIdempotentIdGenerate.java\n"
+ + "具体的幂等策略参考: https://www.easyretry.com/pages/97cde9/#%E2%9A%A1%E5%B9%82%E7%AD%89id-idempotentid \n"
+ +
+ "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
public void remoteRetryWithIdempotentId(@RequestBody OrderVo orderVo) {
- remoteRetryServiceImpl.remoteRetryWithIdempotentId(orderVo);
+ remoteRetryService.remoteRetryWithIdempotentId(orderVo);
}
/**
* 使用自定义的单参数幂等Id生成规则
*/
- @ApiOperation(
- value = "使用自定义的单参数幂等Id生成规则",
- notes =
- "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/SingleParamIdempotentGenerate.java\n"
- +
- "🥇通过对orderId进行md5加密生成幂等ID, 具体的幂等策略参考: https://www.easyretry.com/pages/97cde9/#%E2%9A%A1%E5%B9%82%E7%AD%89id-idempotentid \n"
- +
- "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
+ @Operation(
+ summary = "使用自定义的单参数幂等Id生成规则",
+ description =
+ "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/SingleParamIdempotentGenerate.java\n"
+ +
+ "🥇通过对orderId进行md5加密生成幂等ID, 具体的幂等策略参考: https://www.easyretry.com/pages/97cde9/#%E2%9A%A1%E5%B9%82%E7%AD%89id-idempotentid \n"
+ +
+ "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
@GetMapping("/retryWithSingleParamIdempotentGenerate")
public void retryWithSingleParamIdempotentGenerate(
- @ApiParam(name = "params", value = "测试参数", defaultValue = "test")
- @RequestParam("params") String params) {
- remoteRetryServiceImpl.retryWithSingleParamIdempotentGenerate(params);
+ @Parameter(name = "params", description = "测试参数",
+ schema = @Schema(type = "String", description = "测试参数", defaultValue = "test"))
+ @RequestParam("params") String params) {
+ remoteRetryService.retryWithSingleParamIdempotentGenerate(params);
}
/**
* 使用自定义的多参数幂等Id生成规则
*/
@PostMapping("/retryWithMulParamIdempotentGenerate")
- @ApiOperation(
- value = "使用自定义的多参数幂等Id生成规则",
- notes =
- "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/MultiParamIdempotentGenerate.java\n"
- +
- "🥇通过对orderId进行md5加密生成幂等ID, 具体的幂等策略参考: https://www.easyretry.com/pages/97cde9/#%E2%9A%A1%E5%B9%82%E7%AD%89id-idempotentid \n"
- +
- "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
+ @Operation(
+ summary = "使用自定义的多参数幂等Id生成规则",
+ description =
+ "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/MultiParamIdempotentGenerate.java\n"
+ +
+ "🥇通过对orderId进行md5加密生成幂等ID, 具体的幂等策略参考: https://www.easyretry.com/pages/97cde9/#%E2%9A%A1%E5%B9%82%E7%AD%89id-idempotentid \n"
+ +
+ "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
public void retryWithMulParamIdempotentGenerate(@RequestBody OrderVo orderVo) {
Random random = new Random();
- remoteRetryServiceImpl.retryWithMulParamIdempotentGenerate(
+ remoteRetryService.retryWithMulParamIdempotentGenerate(
String.valueOf(UUID.randomUUID()),
random.nextInt(),
random.nextDouble(),
@@ -111,50 +118,50 @@ public class RemoteRetryController {
/**
* 使用自定义的异常处理类 OrderRetryMethod
*/
- @ApiOperation(
- value = "指定自定义的异常处理类",
- notes =
- "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/OrderRetryMethod.java\n"
- +
- "🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8\n"
- +
- "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
+ @Operation(
+ summary = "指定自定义的异常处理类",
+ description =
+ "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/OrderRetryMethod.java\n"
+ +
+ "🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8\n"
+ +
+ "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
@PostMapping("/retryWithRetryMethod")
public void remoteRetryWithRetryMethod(@RequestBody OrderVo orderVo) {
- remoteRetryServiceImpl.remoteRetryWithRetryMethod(orderVo);
+ remoteRetryService.remoteRetryWithRetryMethod(orderVo);
}
/**
* 使用自定义的回调函数
*/
- @ApiOperation(
- value = "使用自定义的回调函数",
- notes =
- "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/OrderCompleteCallback.java\n"
- +
- "🥇什么情况下触发回调: https://www.easyretry.com/pages/97cde9/#%E2%9A%A1%E5%9B%9E%E8%B0%83\n"
- +
- "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
+ @Operation(
+ summary = "使用自定义的回调函数",
+ description =
+ "具体实现类参考: https://gitee.com/zhangyutongxue/easy-retry-demo/blob/master/easy-retry-springboot/src/main/java/com/maluxinyu/easyretry/customized/OrderCompleteCallback.java\n"
+ +
+ "🥇什么情况下触发回调: https://www.easyretry.com/pages/97cde9/#%E2%9A%A1%E5%9B%9E%E8%B0%83\n"
+ +
+ "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
@PostMapping("/retryWithCallback/{scene}")
public void remoteRetryWithCallback(@ApiParam(name = "scene", value = "场景 FINISH/MAX_COUNT", defaultValue = "FINISH")
@PathVariable("scene") String scene, @RequestBody OrderVo orderVo) {
- remoteRetryServiceImpl.remoteRetryWithCompleteCallback(scene, orderVo);
+ remoteRetryService.remoteRetryWithCompleteCallback(scene, orderVo);
}
/**
* 指定bizNo
*/
- @ApiOperation(
- value = "指定bizNo",
- notes = "🥇什么是bizNo: https://www.easyretry.com/pages/540554/#bizno%E7%94%9F%E6%88%90%E5%99%A8\n"
- +
- "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
+ @Operation(
+ summary = "指定bizNo",
+ description = "🥇什么是bizNo: https://www.easyretry.com/pages/540554/#bizno%E7%94%9F%E6%88%90%E5%99%A8\n"
+ +
+ "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
@PostMapping("/remoteRetryWithBizNo")
public void remoteRetryWithBizNo(@RequestBody OrderVo orderVo) {
- remoteRetryServiceImpl.remoteRetryWithBizNo(orderVo);
+ remoteRetryService.remoteRetryWithBizNo(orderVo);
}
diff --git a/src/main/java/com/example/easy/retry/vo/OrderVo.java b/src/main/java/com/example/easy/retry/vo/OrderVo.java
index 9320692..26c34f4 100644
--- a/src/main/java/com/example/easy/retry/vo/OrderVo.java
+++ b/src/main/java/com/example/easy/retry/vo/OrderVo.java
@@ -4,7 +4,8 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
-import io.swagger.annotations.ApiModelProperty;
+//import io.swagger.annotations.ApiModelProperty;
+import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@@ -15,8 +16,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@Builder
public class OrderVo {
- @ApiModelProperty(value = "订单ID,用于唯一标识订单的编号", required = true)
+ @Schema(description = "订单ID,用于唯一标识订单的编号", accessMode = Schema.AccessMode.READ_WRITE)
private String orderId; // 订单ID,用于唯一标识订单的编号
- @ApiModelProperty(value = "订单来源信息,1-手机端下单 2-PC端下单",required = true)
+ @Schema(description = "订单来源信息,1-手机端下单 2-PC端下单",accessMode = Schema.AccessMode.READ_WRITE)
private Integer source; // 订单来源信息,1-手机端下单 2-PC端下单
}
From c5737690482501452dc6439a69097815c1936603 Mon Sep 17 00:00:00 2001
From: byteblogs168 <598092184@qq.com>
Date: Mon, 4 Sep 2023 22:41:43 +0800
Subject: [PATCH 2/7] =?UTF-8?q?@Schema=20type=E7=9A=84=E5=AD=97=E7=AC=A6?=
=?UTF-8?q?=E4=B8=B2=E7=B1=BB=E5=9E=8B=E4=B8=BAstring?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../retry/controller/LocalAndRemoteRetryController.java | 2 +-
.../example/easy/retry/controller/LocalRetryController.java | 2 +-
.../retry/controller/ManualRetryExecutorController.java | 2 +-
.../easy/retry/controller/RemoteRetryController.java | 6 ++++--
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java b/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java
index b41bad6..6c91fe0 100644
--- a/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java
@@ -34,7 +34,7 @@ public class LocalAndRemoteRetryController {
"📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
public void remoteRetryWithLocalRemote(@Parameter(name = "params", description = "测试参数",
- schema = @Schema(type = "String", description = "测试参数", defaultValue = "test")
+ schema = @Schema(type = "string", description = "测试参数", defaultValue = "test")
)
@RequestParam("params") String params) {
localRemoteService.remoteRetryWithLocalRemote(params);
diff --git a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
index 8266ae8..5613ce2 100644
--- a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
@@ -64,7 +64,7 @@ public class LocalRetryController {
"下面参数可以指定:NullPointerException, ParamException"
)
public void localRetryIncludeException(@Parameter(name = "type", description = "异常类型", in = ParameterIn.QUERY,
- schema = @Schema(type = "String", description = "异常类型")) @RequestParam("type") String type) {
+ schema = @Schema(type = "string", description = "异常类型")) @RequestParam("type") String type) {
localRetryService.localRetryIncludeException(type);
}
diff --git a/src/main/java/com/example/easy/retry/controller/ManualRetryExecutorController.java b/src/main/java/com/example/easy/retry/controller/ManualRetryExecutorController.java
index 302ecef..7d8f5fa 100644
--- a/src/main/java/com/example/easy/retry/controller/ManualRetryExecutorController.java
+++ b/src/main/java/com/example/easy/retry/controller/ManualRetryExecutorController.java
@@ -26,7 +26,7 @@ public class ManualRetryExecutorController {
+ "📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
@GetMapping("/retry")
- public void remoteRetryWithCallback(@Parameter(name = "params", description = "测试参数", schema = @Schema(description = "测试参数", defaultValue = "test"))
+ public void remoteRetryWithCallback(@Parameter(name = "params", description = "测试参数", schema = @Schema(type = "string", description = "测试参数", defaultValue = "test"))
@RequestParam("params") String params) {
manualRetryExecutorMethodService.myExecutorMethod(params);
}
diff --git a/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java b/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
index 0ab0d54..2df9ae4 100644
--- a/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
@@ -2,6 +2,7 @@ package com.example.easy.retry.controller;
import java.util.Random;
import java.util.UUID;
+
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -42,6 +43,7 @@ public class RemoteRetryController {
/**
* 一个最简单的远程调用案例
+ * schema = @Schema(type = "String", defaultValue = "test", description = "测试参数", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
*/
@GetMapping("/retry/sync")
@Operation(
@@ -50,7 +52,7 @@ public class RemoteRetryController {
"📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
public void remoteSync(@Parameter(name = "params", description = "测试参数",
- schema = @Schema(type = "String", defaultValue = "test", description = "测试参数"))
+ schema = @Schema(type = "string", defaultValue = "test", description = "测试参数"))
@RequestParam("params") String params) {
remoteRetryService.remoteSync(params);
}
@@ -86,7 +88,7 @@ public class RemoteRetryController {
@GetMapping("/retryWithSingleParamIdempotentGenerate")
public void retryWithSingleParamIdempotentGenerate(
@Parameter(name = "params", description = "测试参数",
- schema = @Schema(type = "String", description = "测试参数", defaultValue = "test"))
+ schema = @Schema(type = "string", description = "测试参数", defaultValue = "test"))
@RequestParam("params") String params) {
remoteRetryService.retryWithSingleParamIdempotentGenerate(params);
}
From 486f3166b6bb833422bcb7472d9f16d503e2bc2d Mon Sep 17 00:00:00 2001
From: byteblogs168 <598092184@qq.com>
Date: Sat, 16 Sep 2023 12:36:17 +0800
Subject: [PATCH 3/7] =?UTF-8?q?=E5=8D=87=E7=BA=A73.0.0=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../retry/controller/LocalRetryController.java | 18 ++++++++++++------
.../controller/RemoteRetryController.java | 4 +++-
.../easy/retry/service/LocalRemoteService.java | 3 +++
.../ManualRetryExecutorMethodService.java | 1 +
.../service/impl/LocalRemoteServiceImpl.java | 2 ++
5 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
index 5613ce2..4f383b1 100644
--- a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
@@ -1,5 +1,6 @@
package com.example.easy.retry.controller;
+import com.example.easy.retry.vo.OrderVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
@@ -9,6 +10,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -34,10 +37,13 @@ public class LocalRetryController {
}
@GetMapping("/localRetryWithAnnoOnInterface")
- @ApiOperation(
- value = "@Retryable在接口上执行重试"
+ @Operation(
+ summary = "@Retryable在接口上执行重试"
)
- public void localRetryWithAnnoOnInterface(@ApiParam(name = "params", value = "测试参数", defaultValue = "test") @RequestParam("params") String params){
+ public void localRetryWithAnnoOnInterface(
+ @Parameter(name = "params", description = "测试参数", in = ParameterIn.QUERY,
+ schema = @Schema(type = "string", description = "测试参数"))
+ @RequestParam("params") String params) {
localRetryService.localRetryWithAnnoOnInterface(params);
}
@@ -98,9 +104,9 @@ public class LocalRetryController {
/**
* 使用自定义的异常处理类 OrderRetryMethod
*/
- @ApiOperation(
- value = "指定自定义的异常处理类",
- notes ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
+ @Operation(
+ description = "指定自定义的异常处理类",
+ summary ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
)
public boolean localRetryWithRetryMethod(@RequestBody OrderVo orderVo){
return localRetryService.localRetryWithRetryMethod(orderVo);
diff --git a/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java b/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
index 2df9ae4..3135c78 100644
--- a/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
@@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -147,7 +148,8 @@ public class RemoteRetryController {
"📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
)
@PostMapping("/retryWithCallback/{scene}")
- public void remoteRetryWithCallback(@ApiParam(name = "scene", value = "场景 FINISH/MAX_COUNT", defaultValue = "FINISH")
+ public void remoteRetryWithCallback(@Parameter(name = "scene", description = "场景 FINISH/MAX_COUNT",
+ schema = @Schema(type = "string", description = "测试参数", defaultValue = "FINISH"))
@PathVariable("scene") String scene, @RequestBody OrderVo orderVo) {
remoteRetryService.remoteRetryWithCompleteCallback(scene, orderVo);
}
diff --git a/src/main/java/com/example/easy/retry/service/LocalRemoteService.java b/src/main/java/com/example/easy/retry/service/LocalRemoteService.java
index 833d52b..6624a41 100644
--- a/src/main/java/com/example/easy/retry/service/LocalRemoteService.java
+++ b/src/main/java/com/example/easy/retry/service/LocalRemoteService.java
@@ -6,4 +6,7 @@ package com.example.easy.retry.service;
*/
public interface LocalRemoteService {
+ void localRemote();
+
+ String remoteRetryWithLocalRemote(String requestId);
}
diff --git a/src/main/java/com/example/easy/retry/service/ManualRetryExecutorMethodService.java b/src/main/java/com/example/easy/retry/service/ManualRetryExecutorMethodService.java
index ae61ee3..9f2e589 100644
--- a/src/main/java/com/example/easy/retry/service/ManualRetryExecutorMethodService.java
+++ b/src/main/java/com/example/easy/retry/service/ManualRetryExecutorMethodService.java
@@ -6,4 +6,5 @@ package com.example.easy.retry.service;
*/
public interface ManualRetryExecutorMethodService {
+ void myExecutorMethod(String params);
}
diff --git a/src/main/java/com/example/easy/retry/service/impl/LocalRemoteServiceImpl.java b/src/main/java/com/example/easy/retry/service/impl/LocalRemoteServiceImpl.java
index c5b9dd4..d469c22 100644
--- a/src/main/java/com/example/easy/retry/service/impl/LocalRemoteServiceImpl.java
+++ b/src/main/java/com/example/easy/retry/service/impl/LocalRemoteServiceImpl.java
@@ -17,6 +17,7 @@ import java.util.concurrent.TimeUnit;
@Service
public class LocalRemoteServiceImpl implements LocalRemoteService {
+ @Override
@Retryable(scene = "localRemote", retryStrategy = RetryType.LOCAL_REMOTE)
public void localRemote() {
System.out.println("local retry 方法开始执行");
@@ -27,6 +28,7 @@ public class LocalRemoteServiceImpl implements LocalRemoteService {
* 使用先本地再远程的策略同步上传重试请求 retryStrategy = LOCAL_REMOTE 代表本地重试3次后再执行远程上报 async = false 代表使用同步上传的方式 timeout = 1 代表超时时间为1
* unit = MINUTES 代表超时时间的单位是分钟
*/
+ @Override
@Retryable(scene = "remoteRetryWithSync", retryStrategy = RetryType.LOCAL_REMOTE,
async = false, timeout = 1, unit = TimeUnit.MINUTES)
public String remoteRetryWithLocalRemote(String requestId) {
From d174cc65a48f9432946da596d4e2c693e47ec8ac Mon Sep 17 00:00:00 2001
From: byteblogs168 <598092184@qq.com>
Date: Tue, 6 Feb 2024 12:07:49 +0800
Subject: [PATCH 4/7] =?UTF-8?q?=E9=87=8D=E8=AF=95=E6=94=AF=E6=8C=81?=
=?UTF-8?q?=E5=B5=8C=E5=A5=97=E9=87=8D=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 8 +--
.../controller/LocalRetryController.java | 36 +++++++++++++
.../WorkflowCallbackController.java | 1 -
.../easy/retry/handler/RetryHandler.java | 54 +++++++++++++++++++
.../easy/retry/service/LocalRetryService.java | 6 +++
.../service/impl/LocalRetryServiceImpl.java | 27 ++++++++++
6 files changed, 127 insertions(+), 5 deletions(-)
create mode 100644 src/main/java/com/example/easy/retry/handler/RetryHandler.java
diff --git a/pom.xml b/pom.xml
index c65eb97..1385a65 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
com.example
- example
+ example1
1.0.0
example
Demo project for Spring Boot
@@ -38,17 +38,17 @@
com.aizuda
easy-retry-client-starter
- 2.6.0
+ 3.1.0-SNAPSHOT
com.aizuda
easy-retry-client-core
- 2.6.0
+ 3.1.0-SNAPSHOT
com.aizuda
easy-retry-client-job-core
- 2.6.0
+ 3.1.0-SNAPSHOT
org.freemarker
diff --git a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
index 4f383b1..f980e12 100644
--- a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
@@ -111,4 +111,40 @@ public class LocalRetryController {
public boolean localRetryWithRetryMethod(@RequestBody OrderVo orderVo){
return localRetryService.localRetryWithRetryMethod(orderVo);
}
+
+ @GetMapping("/localRetryWithTwoRetryMethod")
+ /**
+ * 使用自定义的异常处理类 OrderRetryMethod
+ */
+ @Operation(
+ description = "指定自定义的异常处理类",
+ summary ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
+ )
+ public boolean localRetryWithTwoRetryMethod(@RequestParam("params") String params){
+ return localRetryService.localRetryWithTwoRetryMethod(params);
+ }
+
+ @GetMapping("/localRetryWithPropagationRequired")
+ /**
+ * 使用自定义的异常处理类 OrderRetryMethod
+ */
+ @Operation(
+ description = "指定自定义的异常处理类",
+ summary ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
+ )
+ public boolean localRetryWithPropagationRequired(@RequestParam("params") String params){
+ return localRetryService.localRetryWithPropagationRequired(params);
+ }
+
+ @GetMapping("/localRetryWithPropagationRequiredNew")
+ /**
+ * 使用自定义的异常处理类 OrderRetryMethod
+ */
+ @Operation(
+ description = "指定自定义的异常处理类",
+ summary ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
+ )
+ public boolean localRetryWithPropagationRequiredNew(@RequestParam("params") String params){
+ return localRetryService.localRetryWithPropagationRequiredNew(params);
+ }
}
diff --git a/src/main/java/com/example/easy/retry/controller/WorkflowCallbackController.java b/src/main/java/com/example/easy/retry/controller/WorkflowCallbackController.java
index 92cbbbe..4a290da 100644
--- a/src/main/java/com/example/easy/retry/controller/WorkflowCallbackController.java
+++ b/src/main/java/com/example/easy/retry/controller/WorkflowCallbackController.java
@@ -1,7 +1,6 @@
package com.example.easy.retry.controller;
import com.aizuda.easy.retry.server.model.dto.CallbackParamsDTO;
-import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
diff --git a/src/main/java/com/example/easy/retry/handler/RetryHandler.java b/src/main/java/com/example/easy/retry/handler/RetryHandler.java
new file mode 100644
index 0000000..bc012ab
--- /dev/null
+++ b/src/main/java/com/example/easy/retry/handler/RetryHandler.java
@@ -0,0 +1,54 @@
+package com.example.easy.retry.handler;
+
+import com.aizuda.easy.retry.client.core.annotation.Propagation;
+import com.aizuda.easy.retry.client.core.annotation.Retryable;
+import com.aizuda.easy.retry.client.core.retryer.RetryType;
+import com.example.easy.retry.vo.OrderVo;
+import org.springframework.stereotype.Component;
+
+import java.util.Random;
+
+/**
+ * @author: xiaowoniu
+ * @date : 2024-02-05
+ * @since : 3.1.0
+ */
+@Component
+public class RetryHandler {
+
+ @Retryable(scene = "localRetryWithTwoRetryMethod1", retryStrategy = RetryType.ONLY_LOCAL)
+ public void retryMethod1(String params) {
+ System.out.println("localRetryWithTwoRetryMethod1");
+ if (params.equals("1")) {
+ throw new RuntimeException("抛出异常");
+ }
+
+ if (params.equals("3")) {
+ int random = new Random().nextInt(10);
+ if (random % 3 == 0) {
+ System.out.println("localRetryWithTwoRetryMethod1 is success");
+ return;
+ }
+
+ throw new RuntimeException("抛出异常");
+ }
+ }
+
+ @Retryable(scene = "localRetryWithTwoRetryMethod2", retryStrategy = RetryType.ONLY_LOCAL)
+ public void retryMethod2(String params) {
+ System.out.println("localRetryWithTwoRetryMethod2");
+ if (params.equals("2")) {
+ throw new RuntimeException("抛出异常");
+ }
+
+ if (params.equals("3")) {
+ throw new RuntimeException("抛出异常");
+ }
+ }
+
+ @Retryable(scene = "localRetry", retryStrategy = RetryType.ONLY_LOCAL, propagation = Propagation.REQUIRES_NEW)
+ public void localRetry(String params) {
+ System.out.println("local retry 方法开始执行");
+ double i = 1 / 0;
+ }
+}
diff --git a/src/main/java/com/example/easy/retry/service/LocalRetryService.java b/src/main/java/com/example/easy/retry/service/LocalRetryService.java
index d36c166..af70aa5 100644
--- a/src/main/java/com/example/easy/retry/service/LocalRetryService.java
+++ b/src/main/java/com/example/easy/retry/service/LocalRetryService.java
@@ -12,6 +12,8 @@ public interface LocalRetryService {
void localRetry(String params);
+ boolean localRetryWithTwoRetryMethod(String params);
+
@Retryable(scene = "localRetryWithAnnoOnInterface", retryStrategy = RetryType.ONLY_LOCAL)
void localRetryWithAnnoOnInterface(String params);
@@ -25,4 +27,8 @@ public interface LocalRetryService {
boolean localRetryWithRetryMethod(OrderVo orderVo);
+ boolean localRetryWithPropagationRequired(String params);
+
+ boolean localRetryWithPropagationRequiredNew(String params);
+
}
diff --git a/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java b/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java
index 87b88e8..c58ed59 100644
--- a/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java
+++ b/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java
@@ -2,8 +2,10 @@ package com.example.easy.retry.service.impl;
import com.aizuda.easy.retry.client.core.retryer.RetryType;
import com.example.easy.retry.customized.OrderRetryMethod;
+import com.example.easy.retry.handler.RetryHandler;
import com.example.easy.retry.service.LocalRetryService;
import com.example.easy.retry.vo.OrderVo;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.aizuda.easy.retry.client.core.annotation.Retryable;
@@ -15,6 +17,10 @@ import com.example.easy.retry.exception.ParamException;
@Component
public class LocalRetryServiceImpl implements LocalRetryService {
+
+ @Autowired
+ private RetryHandler retryHandler;
+
/**
* 入门案例
* 我们仅仅需要指定场景值scene就可以给方法赋予重试逻辑
@@ -30,6 +36,13 @@ public class LocalRetryServiceImpl implements LocalRetryService {
double i = 1 / 0;
}
+ @Override
+ public boolean localRetryWithTwoRetryMethod(final String params) {
+ retryHandler.retryMethod1(params);
+ retryHandler.retryMethod2(params);
+ return true;
+ }
+
@Override
public void localRetryWithAnnoOnInterface(final String params) {
double i = 1 / 0;
@@ -102,4 +115,18 @@ public class LocalRetryServiceImpl implements LocalRetryService {
throw new NullPointerException();
}
+ @Override
+ @Retryable(scene = "localRetryWithPropagationRequired", retryStrategy = RetryType.ONLY_LOCAL)
+ public boolean localRetryWithPropagationRequired(String params) {
+ retryHandler.localRetry(params);
+ return false;
+ }
+
+ @Override
+ @Retryable(scene = "localRetryWithPropagationRequiredNew", retryStrategy = RetryType.ONLY_LOCAL)
+ public boolean localRetryWithPropagationRequiredNew(final String params) {
+ retryHandler.localRetry(params);
+ return false;
+ }
+
}
From 3af97e6a7db3573a1e17f5efc2c500909c471b83 Mon Sep 17 00:00:00 2001
From: byteblogs168 <598092184@qq.com>
Date: Thu, 22 Feb 2024 22:56:08 +0800
Subject: [PATCH 5/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20try=20catch=20?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/demo.sql | 3 +-
.../controller/LocalRetryController.java | 79 ++++++++++++++-----
.../easy/retry/handler/RetryHandler.java | 8 +-
.../easy/retry/service/LocalRetryService.java | 4 +
.../service/impl/LocalRetryServiceImpl.java | 29 ++++++-
5 files changed, 99 insertions(+), 24 deletions(-)
diff --git a/docs/demo.sql b/docs/demo.sql
index 5d678f0..1498ad0 100644
--- a/docs/demo.sql
+++ b/docs/demo.sql
@@ -3,8 +3,7 @@ CREATE DATABASE demo;
USE demo;
CREATE TABLE fail_order
-(
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
+(`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`order_id` varchar(255) NOT NULL COMMENT '订单Id',
`source_id` int NOT NULL COMMENT '来源Id',
`scene_name` varchar(255) NOT NULL COMMENT '场景名称',
diff --git a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
index f980e12..8e741ff 100644
--- a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java
@@ -38,11 +38,11 @@ public class LocalRetryController {
@GetMapping("/localRetryWithAnnoOnInterface")
@Operation(
- summary = "@Retryable在接口上执行重试"
+ summary = "@Retryable在接口上执行重试"
)
public void localRetryWithAnnoOnInterface(
- @Parameter(name = "params", description = "测试参数", in = ParameterIn.QUERY,
- schema = @Schema(type = "string", description = "测试参数"))
+ @Parameter(name = "params", description = "测试参数", in = ParameterIn.QUERY,
+ schema = @Schema(type = "string", description = "测试参数"))
@RequestParam("params") String params) {
localRetryService.localRetryWithAnnoOnInterface(params);
}
@@ -106,45 +106,84 @@ public class LocalRetryController {
*/
@Operation(
description = "指定自定义的异常处理类",
- summary ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
+ summary = "🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
)
- public boolean localRetryWithRetryMethod(@RequestBody OrderVo orderVo){
- return localRetryService.localRetryWithRetryMethod(orderVo);
+ public boolean localRetryWithRetryMethod(@RequestBody OrderVo orderVo) {
+ return localRetryService.localRetryWithRetryMethod(orderVo);
}
@GetMapping("/localRetryWithTwoRetryMethod")
/**
- * 使用自定义的异常处理类 OrderRetryMethod
+ *
+ * 方法内部存在两个串行的方法retryMethod1、retryMethod1 如下所属
+ * public boolean localRetryWithTwoRetryMethod(final String params) {
+ * retryHandler.retryMethod1(params);
+ * retryHandler.retryMethod1(params);
+ * return true;
+ * }
+ * params: 1 => 则retryMethod1触发重试
+ * params: 2 => 则retryMethod2触发重试
+ * params: 3 => 则retryMethod1随机触发重试, 若retryMethod1重试成功,则retryMethod2一定触发重试否则只触发retryMethod1重试
+ *
*/
@Operation(
- description = "指定自定义的异常处理类",
- summary ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
+ summary = "N个串行执行的方法触发重试的场景",
+ description = "方法内部存在两个串行的方法retryMethod1、retryMethod1\n" +
+ "params: 1 => 则retryMethod1触发重试\n" +
+ "params: 2 => 则retryMethod2触发重试\n" +
+ "params: 3 => 则retryMethod1随机触发重试, 若retryMethod1重试成功,则retryMethod2一定触发重试否则只触发retryMethod1重试"
)
- public boolean localRetryWithTwoRetryMethod(@RequestParam("params") String params){
+ public boolean localRetryWithTwoRetryMethod(@RequestParam("params") String params) {
return localRetryService.localRetryWithTwoRetryMethod(params);
}
- @GetMapping("/localRetryWithPropagationRequired")
/**
- * 使用自定义的异常处理类 OrderRetryMethod
+ * 外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED,
+ * 只执行入口方法重试
*/
+ @GetMapping("/localRetryWithPropagationRequired")
@Operation(
- description = "指定自定义的异常处理类",
- summary ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
+ description = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED, 只执行入口方法重试",
+ summary = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED, 只执行入口方法重试"
)
- public boolean localRetryWithPropagationRequired(@RequestParam("params") String params){
+ public boolean localRetryWithPropagationRequired(@RequestParam("params") String params) {
return localRetryService.localRetryWithPropagationRequired(params);
}
- @GetMapping("/localRetryWithPropagationRequiredNew")
/**
- * 使用自定义的异常处理类 OrderRetryMethod
+ * 外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,
+ * 外部和内部方法都触发重试
*/
+ @GetMapping("/localRetryWithPropagationRequiredNew")
@Operation(
- description = "指定自定义的异常处理类",
- summary ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
+ description = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,外部和内部方法都触发重试",
+ summary = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,外部和内部方法都触发重试"
)
- public boolean localRetryWithPropagationRequiredNew(@RequestParam("params") String params){
+ public boolean localRetryWithPropagationRequiredNew(@RequestParam("params") String params) {
return localRetryService.localRetryWithPropagationRequiredNew(params);
}
+
+ /**
+ * 内部方法传播机制为REQUIRED_NEW,且异常被try catch捕获,内部方法触发重试,外部方法不会触发重试
+ */
+ @GetMapping("/localRetryWithTryCatch1")
+ @Operation(
+ description = "",
+ summary = "内部方法传播机制为REQUIRED_NEW,且异常被try catch捕获,内部方法触发重试,外部方法不会触发重试"
+ )
+ public boolean localRetryWithTryCatch1(@RequestParam("params") String params) {
+ return localRetryService.localRetryWithTryCatch1(params);
+ }
+
+ /**
+ * 内部方法传播机制为REQUIRED,且异常被try catch捕获,内部方法不会触发重试,外部方法也不会触发重试
+ */
+ @GetMapping("/localRetryWithTryCatch2")
+ @Operation(
+ description = "",
+ summary = "内部方法传播机制为REQUIRED,且异常被try catch捕获,内部方法不会触发重试,外部方法也不会触发重试"
+ )
+ public boolean localRetryWithTryCatch2(@RequestParam("params") String params) {
+ return localRetryService.localRetryWithTryCatch2(params);
+ }
}
diff --git a/src/main/java/com/example/easy/retry/handler/RetryHandler.java b/src/main/java/com/example/easy/retry/handler/RetryHandler.java
index bc012ab..08f10f6 100644
--- a/src/main/java/com/example/easy/retry/handler/RetryHandler.java
+++ b/src/main/java/com/example/easy/retry/handler/RetryHandler.java
@@ -46,9 +46,15 @@ public class RetryHandler {
}
}
- @Retryable(scene = "localRetry", retryStrategy = RetryType.ONLY_LOCAL, propagation = Propagation.REQUIRES_NEW)
+ @Retryable(scene = "localRetry", retryStrategy = RetryType.ONLY_LOCAL)
public void localRetry(String params) {
System.out.println("local retry 方法开始执行");
double i = 1 / 0;
}
+
+ @Retryable(scene = "localRetryWithRequiresNew", retryStrategy = RetryType.ONLY_LOCAL, propagation = Propagation.REQUIRES_NEW)
+ public void localRetryWithRequiresNew(String params) {
+ System.out.println("local retry 方法开始执行");
+ double i = 1 / 0;
+ }
}
diff --git a/src/main/java/com/example/easy/retry/service/LocalRetryService.java b/src/main/java/com/example/easy/retry/service/LocalRetryService.java
index af70aa5..98e762a 100644
--- a/src/main/java/com/example/easy/retry/service/LocalRetryService.java
+++ b/src/main/java/com/example/easy/retry/service/LocalRetryService.java
@@ -31,4 +31,8 @@ public interface LocalRetryService {
boolean localRetryWithPropagationRequiredNew(String params);
+ boolean localRetryWithTryCatch1(String params);
+
+ boolean localRetryWithTryCatch2(String params);
+
}
diff --git a/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java b/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java
index c58ed59..f654a2e 100644
--- a/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java
+++ b/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java
@@ -5,6 +5,7 @@ import com.example.easy.retry.customized.OrderRetryMethod;
import com.example.easy.retry.handler.RetryHandler;
import com.example.easy.retry.service.LocalRetryService;
import com.example.easy.retry.vo.OrderVo;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -16,6 +17,7 @@ import com.example.easy.retry.exception.ParamException;
*/
@Component
+@Slf4j
public class LocalRetryServiceImpl implements LocalRetryService {
@Autowired
@@ -125,7 +127,32 @@ public class LocalRetryServiceImpl implements LocalRetryService {
@Override
@Retryable(scene = "localRetryWithPropagationRequiredNew", retryStrategy = RetryType.ONLY_LOCAL)
public boolean localRetryWithPropagationRequiredNew(final String params) {
- retryHandler.localRetry(params);
+ retryHandler.localRetryWithRequiresNew(params);
+ return false;
+ }
+
+ @Override
+ @Retryable(scene = "localRetryWithTryCatch1", retryStrategy = RetryType.ONLY_LOCAL)
+ public boolean localRetryWithTryCatch1(String params) {
+ try {
+ // 内部方法需要触发重试
+ retryHandler.localRetryWithRequiresNew(params);
+ } catch (Exception e) {
+ log.error("inner method encountered an exception", e);
+ }
+ return false;
+ }
+
+ @Override
+ @Retryable(scene = "localRetryWithTryCatch2", retryStrategy = RetryType.ONLY_LOCAL)
+ public boolean localRetryWithTryCatch2(String params) {
+ // 由于传播机制为{REQUIRED},异常被捕获,所以内部不会触发重试
+ try {
+ retryHandler.localRetry(params);
+ } catch (Exception e) {
+ log.error("inner method encountered an exception", e);
+ }
+
return false;
}
From f29dae98c4ebfa9e920c6142fc17b2a4c009a0c8 Mon Sep 17 00:00:00 2001
From: byteblogs168 <598092184@qq.com>
Date: Sun, 3 Mar 2024 12:42:04 +0800
Subject: [PATCH 6/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=87=8D=E8=AF=95?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../LocalAndRemoteRetryController.java | 75 +++++++++++++++++++
.../controller/RemoteRetryController.java | 73 ++++++++++++++++++
.../handler/LocalAndRemoteRetryHandler.java | 59 +++++++++++++++
...andler.java => OnlyLocalRetryHandler.java} | 3 +-
.../retry/handler/OnlyRemoteRetryHandler.java | 59 +++++++++++++++
.../retry/service/LocalRemoteService.java | 10 +++
.../retry/service/RemoteRetryService.java | 10 +++
.../service/impl/LocalRemoteServiceImpl.java | 52 +++++++++++++
.../service/impl/LocalRetryServiceImpl.java | 16 ++--
.../service/impl/RemoteRetryServiceImpl.java | 50 ++++++++++++-
10 files changed, 396 insertions(+), 11 deletions(-)
create mode 100644 src/main/java/com/example/easy/retry/handler/LocalAndRemoteRetryHandler.java
rename src/main/java/com/example/easy/retry/handler/{RetryHandler.java => OnlyLocalRetryHandler.java} (96%)
create mode 100644 src/main/java/com/example/easy/retry/handler/OnlyRemoteRetryHandler.java
diff --git a/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java b/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java
index 6c91fe0..f27a583 100644
--- a/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java
@@ -39,4 +39,79 @@ public class LocalAndRemoteRetryController {
@RequestParam("params") String params) {
localRemoteService.remoteRetryWithLocalRemote(params);
}
+
+ @GetMapping("/localRetryWithTwoRetryMethod")
+ /**
+ *
+ * 方法内部存在两个串行的方法retryMethod1、retryMethod1 如下所属
+ * public boolean localRetryWithTwoRetryMethod(final String params) {
+ * retryHandler.retryMethod1(params);
+ * retryHandler.retryMethod1(params);
+ * return true;
+ * }
+ * params: 1 => 则retryMethod1触发重试
+ * params: 2 => 则retryMethod2触发重试
+ * params: 3 => 则retryMethod1随机触发重试, 若retryMethod1重试成功,则retryMethod2一定触发重试否则只触发retryMethod1重试
+ *
+ */
+ @Operation(
+ summary = "N个串行执行的方法触发重试的场景",
+ description = "方法内部存在两个串行的方法retryMethod1、retryMethod1\n" +
+ "params: 1 => 则retryMethod1触发重试\n" +
+ "params: 2 => 则retryMethod2触发重试\n" +
+ "params: 3 => 则retryMethod1随机触发重试, 若retryMethod1重试成功,则retryMethod2一定触发重试否则只触发retryMethod1重试"
+ )
+ public boolean localRetryWithTwoRetryMethod(@RequestParam("params") String params) {
+ return localRemoteService.localRetryWithTwoRetryMethod(params);
+ }
+
+ /**
+ * 外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED,
+ * 只执行入口方法重试
+ */
+ @GetMapping("/localRetryWithPropagationRequired")
+ @Operation(
+ description = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED, 只执行入口方法重试",
+ summary = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED, 只执行入口方法重试"
+ )
+ public boolean localRetryWithPropagationRequired(@RequestParam("params") String params) {
+ return localRemoteService.localRetryWithPropagationRequired(params);
+ }
+
+ /**
+ * 外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,
+ * 外部和内部方法都触发重试
+ */
+ @GetMapping("/localRetryWithPropagationRequiredNew")
+ @Operation(
+ description = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,外部和内部方法都触发重试",
+ summary = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,外部和内部方法都触发重试"
+ )
+ public boolean localRetryWithPropagationRequiredNew(@RequestParam("params") String params) {
+ return localRemoteService.localRetryWithPropagationRequiredNew(params);
+ }
+
+ /**
+ * 内部方法传播机制为REQUIRED_NEW,且异常被try catch捕获,内部方法触发重试,外部方法不会触发重试
+ */
+ @GetMapping("/localRetryWithTryCatch1")
+ @Operation(
+ description = "",
+ summary = "内部方法传播机制为REQUIRED_NEW,且异常被try catch捕获,内部方法触发重试,外部方法不会触发重试"
+ )
+ public boolean localRetryWithTryCatch1(@RequestParam("params") String params) {
+ return localRemoteService.localRetryWithTryCatch1(params);
+ }
+
+ /**
+ * 内部方法传播机制为REQUIRED,且异常被try catch捕获,内部方法不会触发重试,外部方法也不会触发重试
+ */
+ @GetMapping("/localRetryWithTryCatch2")
+ @Operation(
+ description = "",
+ summary = "内部方法传播机制为REQUIRED,且异常被try catch捕获,内部方法不会触发重试,外部方法也不会触发重试"
+ )
+ public boolean localRetryWithTryCatch2(@RequestParam("params") String params) {
+ return localRemoteService.localRetryWithTryCatch2(params);
+ }
}
diff --git a/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java b/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
index 3135c78..b80f8c9 100644
--- a/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
+++ b/src/main/java/com/example/easy/retry/controller/RemoteRetryController.java
@@ -168,5 +168,78 @@ public class RemoteRetryController {
remoteRetryService.remoteRetryWithBizNo(orderVo);
}
+ @GetMapping("/localRetryWithTwoRetryMethod")
+ /**
+ *
+ * 方法内部存在两个串行的方法retryMethod1、retryMethod1 如下所属
+ * public boolean localRetryWithTwoRetryMethod(final String params) {
+ * retryHandler.retryMethod1(params);
+ * retryHandler.retryMethod1(params);
+ * return true;
+ * }
+ * params: 1 => 则retryMethod1触发重试
+ * params: 2 => 则retryMethod2触发重试
+ * params: 3 => 则retryMethod1随机触发重试, 若retryMethod1重试成功,则retryMethod2一定触发重试否则只触发retryMethod1重试
+ *
+ */
+ @Operation(
+ summary = "N个串行执行的方法触发重试的场景",
+ description = "方法内部存在两个串行的方法retryMethod1、retryMethod1\n" +
+ "params: 1 => 则retryMethod1触发重试\n" +
+ "params: 2 => 则retryMethod2触发重试\n" +
+ "params: 3 => 则retryMethod1随机触发重试, 若retryMethod1重试成功,则retryMethod2一定触发重试否则只触发retryMethod1重试"
+ )
+ public boolean localRetryWithTwoRetryMethod(@RequestParam("params") String params) {
+ return remoteRetryService.localRetryWithTwoRetryMethod(params);
+ }
+ /**
+ * 外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED,
+ * 只执行入口方法重试
+ */
+ @GetMapping("/localRetryWithPropagationRequired")
+ @Operation(
+ description = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED, 只执行入口方法重试",
+ summary = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED, 只执行入口方法重试"
+ )
+ public boolean localRetryWithPropagationRequired(@RequestParam("params") String params) {
+ return remoteRetryService.localRetryWithPropagationRequired(params);
+ }
+
+ /**
+ * 外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,
+ * 外部和内部方法都触发重试
+ */
+ @GetMapping("/localRetryWithPropagationRequiredNew")
+ @Operation(
+ description = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,外部和内部方法都触发重试",
+ summary = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,外部和内部方法都触发重试"
+ )
+ public boolean localRetryWithPropagationRequiredNew(@RequestParam("params") String params) {
+ return remoteRetryService.localRetryWithPropagationRequiredNew(params);
+ }
+
+ /**
+ * 内部方法传播机制为REQUIRED_NEW,且异常被try catch捕获,内部方法触发重试,外部方法不会触发重试
+ */
+ @GetMapping("/localRetryWithTryCatch1")
+ @Operation(
+ description = "",
+ summary = "内部方法传播机制为REQUIRED_NEW,且异常被try catch捕获,内部方法触发重试,外部方法不会触发重试"
+ )
+ public boolean localRetryWithTryCatch1(@RequestParam("params") String params) {
+ return remoteRetryService.localRetryWithTryCatch1(params);
+ }
+
+ /**
+ * 内部方法传播机制为REQUIRED,且异常被try catch捕获,内部方法不会触发重试,外部方法也不会触发重试
+ */
+ @GetMapping("/localRetryWithTryCatch2")
+ @Operation(
+ description = "",
+ summary = "内部方法传播机制为REQUIRED,且异常被try catch捕获,内部方法不会触发重试,外部方法也不会触发重试"
+ )
+ public boolean localRetryWithTryCatch2(@RequestParam("params") String params) {
+ return remoteRetryService.localRetryWithTryCatch2(params);
+ }
}
diff --git a/src/main/java/com/example/easy/retry/handler/LocalAndRemoteRetryHandler.java b/src/main/java/com/example/easy/retry/handler/LocalAndRemoteRetryHandler.java
new file mode 100644
index 0000000..3be4d28
--- /dev/null
+++ b/src/main/java/com/example/easy/retry/handler/LocalAndRemoteRetryHandler.java
@@ -0,0 +1,59 @@
+package com.example.easy.retry.handler;
+
+import com.aizuda.easy.retry.client.core.annotation.Propagation;
+import com.aizuda.easy.retry.client.core.annotation.Retryable;
+import com.aizuda.easy.retry.client.core.retryer.RetryType;
+import org.springframework.stereotype.Component;
+
+import java.util.Random;
+
+/**
+ * @author: xiaowoniu
+ * @date : 2024-02-05
+ * @since : 3.1.0
+ */
+@Component
+public class LocalAndRemoteRetryHandler {
+
+ @Retryable(scene = "localRetryWithTwoRetryMethod1", retryStrategy = RetryType.LOCAL_REMOTE)
+ public void retryMethod1(String params) {
+ System.out.println("localRetryWithTwoRetryMethod1");
+ if (params.equals("1")) {
+ throw new RuntimeException("抛出异常");
+ }
+
+ if (params.equals("3")) {
+ int random = new Random().nextInt(10);
+ if (random % 3 == 0) {
+ System.out.println("localRetryWithTwoRetryMethod1 is success");
+ return;
+ }
+
+ throw new RuntimeException("抛出异常");
+ }
+ }
+
+ @Retryable(scene = "localRetryWithTwoRetryMethod2", retryStrategy = RetryType.LOCAL_REMOTE)
+ public void retryMethod2(String params) {
+ System.out.println("localRetryWithTwoRetryMethod2");
+ if (params.equals("2")) {
+ throw new RuntimeException("抛出异常");
+ }
+
+ if (params.equals("3")) {
+ throw new RuntimeException("抛出异常");
+ }
+ }
+
+ @Retryable(scene = "localRetryWithRequires", retryStrategy = RetryType.LOCAL_REMOTE)
+ public void localRetryWithRequires(String params) {
+ System.out.println("local retry 方法开始执行");
+ double i = 1 / 0;
+ }
+
+ @Retryable(scene = "localRetryWithRequiresNew", retryStrategy = RetryType.LOCAL_REMOTE, propagation = Propagation.REQUIRES_NEW)
+ public void localRetryWithRequiresNew(String params) {
+ System.out.println("local retry 方法开始执行");
+ double i = 1 / 0;
+ }
+}
diff --git a/src/main/java/com/example/easy/retry/handler/RetryHandler.java b/src/main/java/com/example/easy/retry/handler/OnlyLocalRetryHandler.java
similarity index 96%
rename from src/main/java/com/example/easy/retry/handler/RetryHandler.java
rename to src/main/java/com/example/easy/retry/handler/OnlyLocalRetryHandler.java
index 08f10f6..3696c74 100644
--- a/src/main/java/com/example/easy/retry/handler/RetryHandler.java
+++ b/src/main/java/com/example/easy/retry/handler/OnlyLocalRetryHandler.java
@@ -3,7 +3,6 @@ package com.example.easy.retry.handler;
import com.aizuda.easy.retry.client.core.annotation.Propagation;
import com.aizuda.easy.retry.client.core.annotation.Retryable;
import com.aizuda.easy.retry.client.core.retryer.RetryType;
-import com.example.easy.retry.vo.OrderVo;
import org.springframework.stereotype.Component;
import java.util.Random;
@@ -14,7 +13,7 @@ import java.util.Random;
* @since : 3.1.0
*/
@Component
-public class RetryHandler {
+public class OnlyLocalRetryHandler {
@Retryable(scene = "localRetryWithTwoRetryMethod1", retryStrategy = RetryType.ONLY_LOCAL)
public void retryMethod1(String params) {
diff --git a/src/main/java/com/example/easy/retry/handler/OnlyRemoteRetryHandler.java b/src/main/java/com/example/easy/retry/handler/OnlyRemoteRetryHandler.java
new file mode 100644
index 0000000..6872021
--- /dev/null
+++ b/src/main/java/com/example/easy/retry/handler/OnlyRemoteRetryHandler.java
@@ -0,0 +1,59 @@
+package com.example.easy.retry.handler;
+
+import com.aizuda.easy.retry.client.core.annotation.Propagation;
+import com.aizuda.easy.retry.client.core.annotation.Retryable;
+import com.aizuda.easy.retry.client.core.retryer.RetryType;
+import org.springframework.stereotype.Component;
+
+import java.util.Random;
+
+/**
+ * @author: xiaowoniu
+ * @date : 2024-02-05
+ * @since : 3.1.0
+ */
+@Component
+public class OnlyRemoteRetryHandler {
+
+ @Retryable(scene = "localRetryWithTwoRetryMethod1", retryStrategy = RetryType.ONLY_LOCAL)
+ public void retryMethod1(String params) {
+ System.out.println("localRetryWithTwoRetryMethod1");
+ if (params.equals("1")) {
+ throw new RuntimeException("抛出异常");
+ }
+
+ if (params.equals("3")) {
+ int random = new Random().nextInt(10);
+ if (random % 3 == 0) {
+ System.out.println("localRetryWithTwoRetryMethod1 is success");
+ return;
+ }
+
+ throw new RuntimeException("抛出异常");
+ }
+ }
+
+ @Retryable(scene = "localRetryWithTwoRetryMethod2", retryStrategy = RetryType.ONLY_LOCAL)
+ public void retryMethod2(String params) {
+ System.out.println("localRetryWithTwoRetryMethod2");
+ if (params.equals("2")) {
+ throw new RuntimeException("抛出异常");
+ }
+
+ if (params.equals("3")) {
+ throw new RuntimeException("抛出异常");
+ }
+ }
+
+ @Retryable(scene = "localRetryWithRequires", retryStrategy = RetryType.ONLY_LOCAL)
+ public void localRetryWithRequires(String params) {
+ System.out.println("local retry 方法开始执行");
+ double i = 1 / 0;
+ }
+
+ @Retryable(scene = "localRetryWithRequiresNew", retryStrategy = RetryType.ONLY_LOCAL, propagation = Propagation.REQUIRES_NEW)
+ public void localRetryWithRequiresNew(String params) {
+ System.out.println("local retry 方法开始执行");
+ double i = 1 / 0;
+ }
+}
diff --git a/src/main/java/com/example/easy/retry/service/LocalRemoteService.java b/src/main/java/com/example/easy/retry/service/LocalRemoteService.java
index 6624a41..58b8a3f 100644
--- a/src/main/java/com/example/easy/retry/service/LocalRemoteService.java
+++ b/src/main/java/com/example/easy/retry/service/LocalRemoteService.java
@@ -9,4 +9,14 @@ public interface LocalRemoteService {
void localRemote();
String remoteRetryWithLocalRemote(String requestId);
+
+ boolean localRetryWithPropagationRequired(String params);
+
+ boolean localRetryWithPropagationRequiredNew(String params);
+
+ boolean localRetryWithTryCatch1(String params);
+
+ boolean localRetryWithTryCatch2(String params);
+
+ boolean localRetryWithTwoRetryMethod(String params);
}
diff --git a/src/main/java/com/example/easy/retry/service/RemoteRetryService.java b/src/main/java/com/example/easy/retry/service/RemoteRetryService.java
index bb0ec63..e661715 100644
--- a/src/main/java/com/example/easy/retry/service/RemoteRetryService.java
+++ b/src/main/java/com/example/easy/retry/service/RemoteRetryService.java
@@ -24,4 +24,14 @@ public interface RemoteRetryService {
boolean remoteRetryWithCompleteCallback(String scene, OrderVo orderVo);
boolean remoteRetryWithBizNo(OrderVo orderVo);
+
+ boolean localRetryWithPropagationRequired(String params);
+
+ boolean localRetryWithPropagationRequiredNew(String params);
+
+ boolean localRetryWithTryCatch1(String params);
+
+ boolean localRetryWithTryCatch2(String params);
+
+ boolean localRetryWithTwoRetryMethod(String params);
}
diff --git a/src/main/java/com/example/easy/retry/service/impl/LocalRemoteServiceImpl.java b/src/main/java/com/example/easy/retry/service/impl/LocalRemoteServiceImpl.java
index d469c22..a561d46 100644
--- a/src/main/java/com/example/easy/retry/service/impl/LocalRemoteServiceImpl.java
+++ b/src/main/java/com/example/easy/retry/service/impl/LocalRemoteServiceImpl.java
@@ -2,7 +2,10 @@ package com.example.easy.retry.service.impl;
import com.aizuda.easy.retry.client.core.annotation.Retryable;
import com.aizuda.easy.retry.client.core.retryer.RetryType;
+import com.example.easy.retry.handler.LocalAndRemoteRetryHandler;
import com.example.easy.retry.service.LocalRemoteService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
@@ -15,7 +18,10 @@ import java.util.concurrent.TimeUnit;
* @since 2.1.0
*/
@Service
+@RequiredArgsConstructor
+@Slf4j
public class LocalRemoteServiceImpl implements LocalRemoteService {
+ private final LocalAndRemoteRetryHandler localAndRemoteRetryHandler;
@Override
@Retryable(scene = "localRemote", retryStrategy = RetryType.LOCAL_REMOTE)
@@ -36,4 +42,50 @@ public class LocalRemoteServiceImpl implements LocalRemoteService {
return requestId;
}
+ @Override
+ @Retryable(scene = "localRetryWithPropagationRequired", retryStrategy = RetryType.LOCAL_REMOTE)
+ public boolean localRetryWithPropagationRequired(String params) {
+ localAndRemoteRetryHandler.localRetryWithRequires(params);
+ return false;
+ }
+
+ @Override
+ @Retryable(scene = "localRetryWithPropagationRequiredNew", retryStrategy = RetryType.LOCAL_REMOTE)
+ public boolean localRetryWithPropagationRequiredNew(String params) {
+ localAndRemoteRetryHandler.localRetryWithRequiresNew(params);
+ return false;
+ }
+
+ @Override
+ @Retryable(scene = "localRetryWithTryCatch1", retryStrategy = RetryType.LOCAL_REMOTE)
+ public boolean localRetryWithTryCatch1(String params) {
+ try {
+ // 内部方法需要触发重试
+ localAndRemoteRetryHandler.localRetryWithRequiresNew(params);
+ } catch (Exception e) {
+ log.error("inner method encountered an exception", e);
+ }
+ return false;
+ }
+
+ @Override
+ @Retryable(scene = "localRetryWithTryCatch2", retryStrategy = RetryType.LOCAL_REMOTE)
+ public boolean localRetryWithTryCatch2(String params) {
+ // 由于传播机制为{REQUIRED},异常被捕获,所以内部不会触发重试
+ try {
+ localAndRemoteRetryHandler.localRetryWithRequires(params);
+ } catch (Exception e) {
+ log.error("inner method encountered an exception", e);
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean localRetryWithTwoRetryMethod(String params) {
+ localAndRemoteRetryHandler.retryMethod1(params);
+ localAndRemoteRetryHandler.retryMethod2(params);
+ return false;
+ }
+
}
diff --git a/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java b/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java
index f654a2e..da889b8 100644
--- a/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java
+++ b/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java
@@ -2,7 +2,7 @@ package com.example.easy.retry.service.impl;
import com.aizuda.easy.retry.client.core.retryer.RetryType;
import com.example.easy.retry.customized.OrderRetryMethod;
-import com.example.easy.retry.handler.RetryHandler;
+import com.example.easy.retry.handler.OnlyLocalRetryHandler;
import com.example.easy.retry.service.LocalRetryService;
import com.example.easy.retry.vo.OrderVo;
import lombok.extern.slf4j.Slf4j;
@@ -21,7 +21,7 @@ import com.example.easy.retry.exception.ParamException;
public class LocalRetryServiceImpl implements LocalRetryService {
@Autowired
- private RetryHandler retryHandler;
+ private OnlyLocalRetryHandler onlyLocalRetryHandler;
/**
* 入门案例
@@ -40,8 +40,8 @@ public class LocalRetryServiceImpl implements LocalRetryService {
@Override
public boolean localRetryWithTwoRetryMethod(final String params) {
- retryHandler.retryMethod1(params);
- retryHandler.retryMethod2(params);
+ onlyLocalRetryHandler.retryMethod1(params);
+ onlyLocalRetryHandler.retryMethod2(params);
return true;
}
@@ -120,14 +120,14 @@ public class LocalRetryServiceImpl implements LocalRetryService {
@Override
@Retryable(scene = "localRetryWithPropagationRequired", retryStrategy = RetryType.ONLY_LOCAL)
public boolean localRetryWithPropagationRequired(String params) {
- retryHandler.localRetry(params);
+ onlyLocalRetryHandler.localRetry(params);
return false;
}
@Override
@Retryable(scene = "localRetryWithPropagationRequiredNew", retryStrategy = RetryType.ONLY_LOCAL)
public boolean localRetryWithPropagationRequiredNew(final String params) {
- retryHandler.localRetryWithRequiresNew(params);
+ onlyLocalRetryHandler.localRetryWithRequiresNew(params);
return false;
}
@@ -136,7 +136,7 @@ public class LocalRetryServiceImpl implements LocalRetryService {
public boolean localRetryWithTryCatch1(String params) {
try {
// 内部方法需要触发重试
- retryHandler.localRetryWithRequiresNew(params);
+ onlyLocalRetryHandler.localRetryWithRequiresNew(params);
} catch (Exception e) {
log.error("inner method encountered an exception", e);
}
@@ -148,7 +148,7 @@ public class LocalRetryServiceImpl implements LocalRetryService {
public boolean localRetryWithTryCatch2(String params) {
// 由于传播机制为{REQUIRED},异常被捕获,所以内部不会触发重试
try {
- retryHandler.localRetry(params);
+ onlyLocalRetryHandler.localRetry(params);
} catch (Exception e) {
log.error("inner method encountered an exception", e);
}
diff --git a/src/main/java/com/example/easy/retry/service/impl/RemoteRetryServiceImpl.java b/src/main/java/com/example/easy/retry/service/impl/RemoteRetryServiceImpl.java
index 7e50574..4623e32 100644
--- a/src/main/java/com/example/easy/retry/service/impl/RemoteRetryServiceImpl.java
+++ b/src/main/java/com/example/easy/retry/service/impl/RemoteRetryServiceImpl.java
@@ -6,7 +6,10 @@ import java.util.concurrent.TimeUnit;
import cn.hutool.core.lang.Assert;
import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
+import com.example.easy.retry.handler.OnlyRemoteRetryHandler;
import com.example.easy.retry.service.RemoteRetryService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import com.aizuda.easy.retry.client.core.annotation.Retryable;
@@ -22,8 +25,10 @@ import com.example.easy.retry.vo.OrderVo;
* easy-retry中的远程重试
*/
@Component
+@Slf4j
+@RequiredArgsConstructor
public class RemoteRetryServiceImpl implements RemoteRetryService {
-
+ private final OnlyRemoteRetryHandler onlyRemoteRetryHandler;
/**
* 定义一个最基本的远程重试方法
*/
@@ -91,6 +96,49 @@ public class RemoteRetryServiceImpl implements RemoteRetryService {
throw new NullPointerException();
}
+ @Override
+ @Retryable(scene = "localRetryWithPropagationRequired", retryStrategy = RetryType.LOCAL_REMOTE)
+ public boolean localRetryWithPropagationRequired(String params) {
+ onlyRemoteRetryHandler.localRetryWithRequires(params);
+ return false;
+ }
+
+ @Override
+ public boolean localRetryWithPropagationRequiredNew(String params) {
+ onlyRemoteRetryHandler.localRetryWithRequiresNew(params);
+ return false;
+ }
+
+ @Override
+ public boolean localRetryWithTryCatch1(String params) {
+ try {
+ // 内部方法需要触发重试
+ onlyRemoteRetryHandler.localRetryWithRequiresNew(params);
+ } catch (Exception e) {
+ log.error("inner method encountered an exception", e);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean localRetryWithTryCatch2(String params) {
+ // 由于传播机制为{REQUIRED},异常被捕获,所以内部不会触发重试
+ try {
+ onlyRemoteRetryHandler.localRetryWithRequires(params);
+ } catch (Exception e) {
+ log.error("inner method encountered an exception", e);
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean localRetryWithTwoRetryMethod(String params) {
+ onlyRemoteRetryHandler.retryMethod1(params);
+ onlyRemoteRetryHandler.retryMethod2(params);
+ return false;
+ }
+
/**
* 使用自定义的retryCompleteCallback类 OrderCompleteCallback
*/
From 0d8d37ea4f7baf1b32a6dc609ab0e00d2568b33d Mon Sep 17 00:00:00 2001
From: byteblogs168 <598092184@qq.com>
Date: Sun, 3 Mar 2024 23:03:35 +0800
Subject: [PATCH 7/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../easy/retry/controller/WorkflowCallbackController.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/main/java/com/example/easy/retry/controller/WorkflowCallbackController.java b/src/main/java/com/example/easy/retry/controller/WorkflowCallbackController.java
index 4a290da..527ff2b 100644
--- a/src/main/java/com/example/easy/retry/controller/WorkflowCallbackController.java
+++ b/src/main/java/com/example/easy/retry/controller/WorkflowCallbackController.java
@@ -1,6 +1,7 @@
package com.example.easy.retry.controller;
import com.aizuda.easy.retry.server.model.dto.CallbackParamsDTO;
+import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
@@ -15,6 +16,7 @@ import java.util.List;
@RestController
@RequestMapping("/workflow/callback")
@Slf4j
+@Tag(name = "工作流回调", description = "工作流回调")
public class WorkflowCallbackController {
@PostMapping