Merge branch '3.x'
# Conflicts: # pom.xml # src/main/java/com/example/easy/retry/controller/LocalAndRemoteRetryController.java # src/main/java/com/example/easy/retry/controller/LocalRetryController.java # src/main/java/com/example/easy/retry/service/LocalRemoteService.java
This commit is contained in:
commit
0d00e62e9e
@ -3,8 +3,7 @@ CREATE DATABASE demo;
|
|||||||
USE demo;
|
USE demo;
|
||||||
|
|
||||||
CREATE TABLE fail_order
|
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',
|
`order_id` varchar(255) NOT NULL COMMENT '订单Id',
|
||||||
`source_id` int NOT NULL COMMENT '来源Id',
|
`source_id` int NOT NULL COMMENT '来源Id',
|
||||||
`scene_name` varchar(255) NOT NULL COMMENT '场景名称',
|
`scene_name` varchar(255) NOT NULL COMMENT '场景名称',
|
||||||
|
8
pom.xml
8
pom.xml
@ -10,7 +10,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>example</artifactId>
|
<artifactId>example1</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<name>example</name>
|
<name>example</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
@ -38,17 +38,17 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aizuda</groupId>
|
<groupId>com.aizuda</groupId>
|
||||||
<artifactId>easy-retry-client-starter</artifactId>
|
<artifactId>easy-retry-client-starter</artifactId>
|
||||||
<version>2.6.1</version>
|
<version>3.1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aizuda</groupId>
|
<groupId>com.aizuda</groupId>
|
||||||
<artifactId>easy-retry-client-core</artifactId>
|
<artifactId>easy-retry-client-core</artifactId>
|
||||||
<version>2.6.1</version>
|
<version>3.1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aizuda</groupId>
|
<groupId>com.aizuda</groupId>
|
||||||
<artifactId>easy-retry-client-job-core</artifactId>
|
<artifactId>easy-retry-client-job-core</artifactId>
|
||||||
<version>2.6.1</version>
|
<version>3.1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.freemarker</groupId>
|
<groupId>org.freemarker</groupId>
|
||||||
|
@ -39,4 +39,79 @@ public class LocalAndRemoteRetryController {
|
|||||||
@RequestParam("params") String params) {
|
@RequestParam("params") String params) {
|
||||||
localRemoteService.remoteRetryWithLocalRemote(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,9 +106,84 @@ public class LocalRetryController {
|
|||||||
*/
|
*/
|
||||||
@Operation(
|
@Operation(
|
||||||
description = "指定自定义的异常处理类",
|
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){
|
public boolean localRetryWithRetryMethod(@RequestBody OrderVo orderVo) {
|
||||||
return localRetryService.localRetryWithRetryMethod(orderVo);
|
return localRetryService.localRetryWithRetryMethod(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 localRetryService.localRetryWithTwoRetryMethod(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED,
|
||||||
|
* 只执行入口方法重试
|
||||||
|
*/
|
||||||
|
@GetMapping("/localRetryWithPropagationRequired")
|
||||||
|
@Operation(
|
||||||
|
description = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED, 只执行入口方法重试",
|
||||||
|
summary = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED, 只执行入口方法重试"
|
||||||
|
)
|
||||||
|
public boolean localRetryWithPropagationRequired(@RequestParam("params") String params) {
|
||||||
|
return localRetryService.localRetryWithPropagationRequired(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,
|
||||||
|
* 外部和内部方法都触发重试
|
||||||
|
*/
|
||||||
|
@GetMapping("/localRetryWithPropagationRequiredNew")
|
||||||
|
@Operation(
|
||||||
|
description = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,外部和内部方法都触发重试",
|
||||||
|
summary = "外部方法传播机制为REQUIRED,内部方法传播机制为REQUIRED_NEW,外部和内部方法都触发重试"
|
||||||
|
)
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,5 +168,78 @@ public class RemoteRetryController {
|
|||||||
remoteRetryService.remoteRetryWithBizNo(orderVo);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.example.easy.retry.controller;
|
package com.example.easy.retry.controller;
|
||||||
|
|
||||||
import com.aizuda.easy.retry.server.model.dto.CallbackParamsDTO;
|
import com.aizuda.easy.retry.server.model.dto.CallbackParamsDTO;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -16,6 +16,7 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/workflow/callback")
|
@RequestMapping("/workflow/callback")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Tag(name = "工作流回调", description = "工作流回调")
|
||||||
public class WorkflowCallbackController {
|
public class WorkflowCallbackController {
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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 OnlyLocalRetryHandler {
|
||||||
|
|
||||||
|
@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)
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -9,4 +9,14 @@ public interface LocalRemoteService {
|
|||||||
void localRemote();
|
void localRemote();
|
||||||
|
|
||||||
String remoteRetryWithLocalRemote(String requestId);
|
String remoteRetryWithLocalRemote(String requestId);
|
||||||
|
|
||||||
|
boolean localRetryWithPropagationRequired(String params);
|
||||||
|
|
||||||
|
boolean localRetryWithPropagationRequiredNew(String params);
|
||||||
|
|
||||||
|
boolean localRetryWithTryCatch1(String params);
|
||||||
|
|
||||||
|
boolean localRetryWithTryCatch2(String params);
|
||||||
|
|
||||||
|
boolean localRetryWithTwoRetryMethod(String params);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ public interface LocalRetryService {
|
|||||||
|
|
||||||
void localRetry(String params);
|
void localRetry(String params);
|
||||||
|
|
||||||
|
boolean localRetryWithTwoRetryMethod(String params);
|
||||||
|
|
||||||
@Retryable(scene = "localRetryWithAnnoOnInterface", retryStrategy = RetryType.ONLY_LOCAL)
|
@Retryable(scene = "localRetryWithAnnoOnInterface", retryStrategy = RetryType.ONLY_LOCAL)
|
||||||
void localRetryWithAnnoOnInterface(String params);
|
void localRetryWithAnnoOnInterface(String params);
|
||||||
|
|
||||||
@ -25,4 +27,12 @@ public interface LocalRetryService {
|
|||||||
|
|
||||||
boolean localRetryWithRetryMethod(OrderVo orderVo);
|
boolean localRetryWithRetryMethod(OrderVo orderVo);
|
||||||
|
|
||||||
|
boolean localRetryWithPropagationRequired(String params);
|
||||||
|
|
||||||
|
boolean localRetryWithPropagationRequiredNew(String params);
|
||||||
|
|
||||||
|
boolean localRetryWithTryCatch1(String params);
|
||||||
|
|
||||||
|
boolean localRetryWithTryCatch2(String params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,4 +24,14 @@ public interface RemoteRetryService {
|
|||||||
boolean remoteRetryWithCompleteCallback(String scene, OrderVo orderVo);
|
boolean remoteRetryWithCompleteCallback(String scene, OrderVo orderVo);
|
||||||
|
|
||||||
boolean remoteRetryWithBizNo(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);
|
||||||
}
|
}
|
||||||
|
@ -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.annotation.Retryable;
|
||||||
import com.aizuda.easy.retry.client.core.retryer.RetryType;
|
import com.aizuda.easy.retry.client.core.retryer.RetryType;
|
||||||
|
import com.example.easy.retry.handler.LocalAndRemoteRetryHandler;
|
||||||
import com.example.easy.retry.service.LocalRemoteService;
|
import com.example.easy.retry.service.LocalRemoteService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -15,7 +18,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class LocalRemoteServiceImpl implements LocalRemoteService {
|
public class LocalRemoteServiceImpl implements LocalRemoteService {
|
||||||
|
private final LocalAndRemoteRetryHandler localAndRemoteRetryHandler;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Retryable(scene = "localRemote", retryStrategy = RetryType.LOCAL_REMOTE)
|
@Retryable(scene = "localRemote", retryStrategy = RetryType.LOCAL_REMOTE)
|
||||||
@ -36,4 +42,50 @@ public class LocalRemoteServiceImpl implements LocalRemoteService {
|
|||||||
return requestId;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,11 @@ package com.example.easy.retry.service.impl;
|
|||||||
|
|
||||||
import com.aizuda.easy.retry.client.core.retryer.RetryType;
|
import com.aizuda.easy.retry.client.core.retryer.RetryType;
|
||||||
import com.example.easy.retry.customized.OrderRetryMethod;
|
import com.example.easy.retry.customized.OrderRetryMethod;
|
||||||
|
import com.example.easy.retry.handler.OnlyLocalRetryHandler;
|
||||||
import com.example.easy.retry.service.LocalRetryService;
|
import com.example.easy.retry.service.LocalRetryService;
|
||||||
import com.example.easy.retry.vo.OrderVo;
|
import com.example.easy.retry.vo.OrderVo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||||
@ -14,7 +17,12 @@ import com.example.easy.retry.exception.ParamException;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class LocalRetryServiceImpl implements LocalRetryService {
|
public class LocalRetryServiceImpl implements LocalRetryService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OnlyLocalRetryHandler onlyLocalRetryHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 入门案例
|
* 入门案例
|
||||||
* 我们仅仅需要指定场景值scene就可以给方法赋予重试逻辑
|
* 我们仅仅需要指定场景值scene就可以给方法赋予重试逻辑
|
||||||
@ -30,6 +38,13 @@ public class LocalRetryServiceImpl implements LocalRetryService {
|
|||||||
double i = 1 / 0;
|
double i = 1 / 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean localRetryWithTwoRetryMethod(final String params) {
|
||||||
|
onlyLocalRetryHandler.retryMethod1(params);
|
||||||
|
onlyLocalRetryHandler.retryMethod2(params);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void localRetryWithAnnoOnInterface(final String params) {
|
public void localRetryWithAnnoOnInterface(final String params) {
|
||||||
double i = 1 / 0;
|
double i = 1 / 0;
|
||||||
@ -102,4 +117,43 @@ public class LocalRetryServiceImpl implements LocalRetryService {
|
|||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Retryable(scene = "localRetryWithPropagationRequired", retryStrategy = RetryType.ONLY_LOCAL)
|
||||||
|
public boolean localRetryWithPropagationRequired(String params) {
|
||||||
|
onlyLocalRetryHandler.localRetry(params);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Retryable(scene = "localRetryWithPropagationRequiredNew", retryStrategy = RetryType.ONLY_LOCAL)
|
||||||
|
public boolean localRetryWithPropagationRequiredNew(final String params) {
|
||||||
|
onlyLocalRetryHandler.localRetryWithRequiresNew(params);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Retryable(scene = "localRetryWithTryCatch1", retryStrategy = RetryType.ONLY_LOCAL)
|
||||||
|
public boolean localRetryWithTryCatch1(String params) {
|
||||||
|
try {
|
||||||
|
// 内部方法需要触发重试
|
||||||
|
onlyLocalRetryHandler.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 {
|
||||||
|
onlyLocalRetryHandler.localRetry(params);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("inner method encountered an exception", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot;
|
import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot;
|
||||||
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
|
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
|
||||||
|
import com.example.easy.retry.handler.OnlyRemoteRetryHandler;
|
||||||
import com.example.easy.retry.service.RemoteRetryService;
|
import com.example.easy.retry.service.RemoteRetryService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||||
@ -22,8 +25,10 @@ import com.example.easy.retry.vo.OrderVo;
|
|||||||
* easy-retry中的远程重试
|
* easy-retry中的远程重试
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class RemoteRetryServiceImpl implements RemoteRetryService {
|
public class RemoteRetryServiceImpl implements RemoteRetryService {
|
||||||
|
private final OnlyRemoteRetryHandler onlyRemoteRetryHandler;
|
||||||
/**
|
/**
|
||||||
* 定义一个最基本的远程重试方法
|
* 定义一个最基本的远程重试方法
|
||||||
*/
|
*/
|
||||||
@ -91,6 +96,49 @@ public class RemoteRetryServiceImpl implements RemoteRetryService {
|
|||||||
throw new NullPointerException();
|
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
|
* 使用自定义的retryCompleteCallback类 OrderCompleteCallback
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user