feat: 2.0.0

1. 优化IdempotentIdContext注释
2. 手动生成幂等号改为IdempotentIdContext传参
This commit is contained in:
www.byteblogs.com 2023-06-28 23:46:03 +08:00
parent d1fa72cfe9
commit 808bcfe0be
4 changed files with 27 additions and 7 deletions

View File

@ -27,9 +27,9 @@ public interface IdempotentIdGenerate {
* 3: 执行的方法名称: methodName(String)
* scene, targetClassName, args, executorMethod.getName()
*
* @param idempotentIdContext
* @param context {@link IdempotentIdContext} 幂等id生成器上下文
* @return idempotentId
* @throws Exception
*/
String idGenerate(IdempotentIdContext idempotentIdContext) throws Exception;
String idGenerate(IdempotentIdContext context) throws Exception;
}

View File

@ -17,6 +17,7 @@ import com.aizuda.easy.retry.common.core.context.SpringContext;
import com.aizuda.easy.retry.common.core.enums.RetryResultStatusEnum;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.common.core.model.IdempotentIdContext;
import com.aizuda.easy.retry.common.core.model.Result;
import com.aizuda.easy.retry.common.core.util.JsonUtil;
import com.aizuda.easy.retry.server.model.dto.ConfigDTO;
@ -178,9 +179,9 @@ public class RetryEndPoint {
try {
Class<? extends IdempotentIdGenerate> idempotentIdGenerate = retryerInfo.getIdempotentIdGenerate();
IdempotentIdGenerate generate = idempotentIdGenerate.newInstance();
Method method = idempotentIdGenerate.getMethod("idGenerate", Object[].class);
Object p = new Object[]{scene, executorName, deSerialize, executorMethod.getName()};
idempotentId = (String) ReflectionUtils.invokeMethod(method, generate, p);
Method method = idempotentIdGenerate.getMethod("idGenerate", IdempotentIdContext.class);
IdempotentIdContext idempotentIdContext = new IdempotentIdContext(scene, executorName, deSerialize, executorMethod.getName());
idempotentId = (String) ReflectionUtils.invokeMethod(method, generate, idempotentIdContext);
} catch (Exception exception) {
LogUtils.error(log, "幂等id生成异常{},{}", scene, argsStr, exception);
throw new EasyRetryClientException("idempotentId生成异常{},{}", scene, argsStr);

View File

@ -13,7 +13,7 @@ import com.aizuda.easy.retry.common.core.model.IdempotentIdContext;
public class SimpleIdempotentIdGenerate implements IdempotentIdGenerate {
@Override
public String idGenerate(IdempotentIdContext idempotentIdContext) throws Exception {
return SecureUtil.md5(idempotentIdContext.toString());
public String idGenerate(IdempotentIdContext context) throws Exception {
return SecureUtil.md5(context.toString());
}
}

View File

@ -3,16 +3,35 @@ package com.aizuda.easy.retry.common.core.model;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* 幂等id上下文
*
* @author zy9567
* @date 2023-06-28 19:03
* @since 2.0.0
*/
@Data
@AllArgsConstructor
public class IdempotentIdContext {
/**
* 场景名称
*/
private String scene;
/**
* 执行器名称
*/
private String targetClassName;
/**
* 参数列表
*/
private Object[] args;
/**
* 执行的方法名称
*/
private String methodName;
}