diff --git a/pom.xml b/pom.xml index 7bcb33b..1805566 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..6c91fe0 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..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,93 +1,102 @@ 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.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.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); } @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); } @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); } @@ -95,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/ManualRetryExecutorController.java b/src/main/java/com/example/easy/retry/controller/ManualRetryExecutorController.java index eb44a51..7d8f5fa 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(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 d2ab539..3135c78 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,115 @@ 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.PathVariable; +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); } /** * 一个最简单的远程调用案例 + * schema = @Schema(type = "String", defaultValue = "test", description = "测试参数", requiredMode = Schema.RequiredMode.NOT_REQUIRED) */ @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 +121,51 @@ 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") + public void remoteRetryWithCallback(@Parameter(name = "scene", description = "场景 FINISH/MAX_COUNT", + schema = @Schema(type = "string", description = "测试参数", 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/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) { 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端下单 }