修复测试最大次数回调 demo的sql异常
This commit is contained in:
parent
203ec502d8
commit
258971f199
@ -2,14 +2,15 @@ DROP DATABASE IF EXISTS demo;
|
||||
CREATE DATABASE demo;
|
||||
USE demo;
|
||||
|
||||
CREATE TABLE `demo`.`fail_order` (
|
||||
`id` bigint NOT NULL COMMENT '自增主键Id',
|
||||
`orderId` bigint NOT NULL COMMENT '订单Id',
|
||||
`sourceId` int NOT NULL COMMENT '来源Id',
|
||||
`sceneName` varchar(255) NOT NULL COMMENT '场景名称',
|
||||
`executorName` varchar(255) NOT NULL COMMENT '执行器名称',
|
||||
`args` varchar(255) NULL COMMENT '参数信息',
|
||||
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
CREATE TABLE fail_order
|
||||
(
|
||||
`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 '场景名称',
|
||||
`executor_name` varchar(255) NOT NULL COMMENT '执行器名称',
|
||||
`args` varchar(255) NULL COMMENT '参数信息',
|
||||
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
@ -8,12 +8,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.example.easy.retry.vo.OrderVo;
|
||||
import com.example.easy.retry.service.impl.RemoteRetryServiceImpl;
|
||||
@ -142,9 +137,10 @@ public class RemoteRetryController {
|
||||
+
|
||||
"📢查看任务列表: http://preview.easyretry.com/#/retry-task/list"
|
||||
)
|
||||
@PostMapping("/retryWithCallback")
|
||||
public void remoteRetryWithCallback(@RequestBody OrderVo orderVo) {
|
||||
remoteRetryServiceImpl.remoteRetryWithCompleteCallback(orderVo);
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,8 @@ package com.example.easy.retry.customized;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.aizuda.easy.retry.client.core.callback.RetryCompleteCallback;
|
||||
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.example.easy.retry.dao.FailOrderBaseMapper;
|
||||
import com.example.easy.retry.po.FailOrderPo;
|
||||
@ -26,10 +28,10 @@ public class OrderCompleteCallback implements RetryCompleteCallback {
|
||||
@Override
|
||||
public void doSuccessCallback(String sceneName, String executorName, Object[] objects) {
|
||||
// 重试成功后删除失败表中的数据
|
||||
OrderVo orderVo = (OrderVo) objects[0];
|
||||
OrderVo orderVo = JsonUtil.parseObject(JsonUtil.toJsonString(objects[1]), OrderVo.class);
|
||||
log.info("远程重试成功,场景{},执行器{},参数信息",sceneName,executorName, JSONUtil.toJsonStr(objects));
|
||||
failOrderBaseMapper.delete(
|
||||
new LambdaQueryChainWrapper<>(failOrderBaseMapper)
|
||||
new LambdaQueryWrapper<FailOrderPo>()
|
||||
.eq(FailOrderPo::getOrderId,orderVo.getOrderId())
|
||||
);
|
||||
}
|
||||
@ -42,7 +44,7 @@ public class OrderCompleteCallback implements RetryCompleteCallback {
|
||||
*/
|
||||
@Override
|
||||
public void doMaxRetryCallback(String sceneName, String executorName, Object[] objects) {
|
||||
OrderVo orderVo = (OrderVo) objects[0];
|
||||
OrderVo orderVo = JsonUtil.parseObject(JsonUtil.toJsonString(objects[1]), OrderVo.class);
|
||||
log.info("远程重试达到最大限度,场景{},执行器{},参数信息",sceneName,executorName, JSONUtil.toJsonStr(objects));
|
||||
// 重试失败后插入订单失败信息
|
||||
failOrderBaseMapper.insert(FailOrderPo.builder()
|
||||
|
@ -21,7 +21,7 @@ public interface RemoteRetryService {
|
||||
|
||||
boolean remoteRetryWithRetryMethod(OrderVo orderVo);
|
||||
|
||||
boolean remoteRetryWithCompleteCallback(OrderVo orderVo);
|
||||
boolean remoteRetryWithCompleteCallback(String scene, OrderVo orderVo);
|
||||
|
||||
boolean remoteRetryWithBizNo(OrderVo orderVo);
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ package com.example.easy.retry.service.impl;
|
||||
import java.util.Random;
|
||||
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.service.RemoteRetryService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -80,23 +83,6 @@ public class RemoteRetryServiceImpl implements RemoteRetryService {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用自定义的retryCompleteCallback类 OrderCompleteCallback
|
||||
*/
|
||||
@Retryable(scene = "remoteRetryWithCompleteCallback", retryStrategy = RetryType.LOCAL_REMOTE,
|
||||
retryCompleteCallback = OrderCompleteCallback.class)
|
||||
public boolean remoteRetryWithCompleteCallback(OrderVo orderVo) {
|
||||
Random random = new Random();
|
||||
// 生成一个随机数,范围为0到1之间
|
||||
double probability = random.nextDouble();
|
||||
// 判断随机数是否小于等于0.5,即50%的概率
|
||||
if (probability <= 0.5) {
|
||||
// 生成的结果在50%的概率下执行这里的逻辑
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义BizNo
|
||||
*/
|
||||
@ -105,5 +91,27 @@ public class RemoteRetryServiceImpl implements RemoteRetryService {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用自定义的retryCompleteCallback类 OrderCompleteCallback
|
||||
*/
|
||||
@Retryable(scene = "remoteRetryWithCompleteCallback", retryStrategy = RetryType.ONLY_REMOTE,
|
||||
retryCompleteCallback = OrderCompleteCallback.class)
|
||||
public boolean remoteRetryWithCompleteCallback(String scene, OrderVo orderVo) {
|
||||
|
||||
Assert.notNull(RetrySiteSnapshot.getStage(), ()->new IllegalArgumentException("测试回调"));
|
||||
|
||||
// 本地重试阶段,执行失败,远程的执行成功
|
||||
if (RetrySiteSnapshot.getStage().equals(RetrySiteSnapshot.EnumStage.LOCAL.getStage())) {
|
||||
// 生成的结果在50%的概率下执行这里的逻辑
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
if (scene.equals(RetryStatusEnum.MAX_COUNT.name())) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user