feat: 2.0.0
提交修改IdempotentIdGenerate接受对象
This commit is contained in:
parent
789c6f3a9f
commit
d1fa72cfe9
@ -1,5 +1,7 @@
|
||||
package com.aizuda.easy.retry.client.core;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.model.IdempotentIdContext;
|
||||
|
||||
/**
|
||||
* 幂等id生成器
|
||||
* 同一个组的同一个场景下只会存在一个相同的idempotentId重试任务, 若存在相同的则上报服务后会被幂等处理
|
||||
@ -25,9 +27,9 @@ public interface IdempotentIdGenerate {
|
||||
* 3: 执行的方法名称: methodName(String)
|
||||
* scene, targetClassName, args, executorMethod.getName()
|
||||
*
|
||||
* @param t 参数列表
|
||||
* @param idempotentIdContext
|
||||
* @return idempotentId
|
||||
* @throws Exception
|
||||
*/
|
||||
String idGenerate(Object... t) throws Exception;
|
||||
String idGenerate(IdempotentIdContext idempotentIdContext) throws Exception;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package com.aizuda.easy.retry.client.core.generator;
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.aizuda.easy.retry.client.core.IdempotentIdGenerate;
|
||||
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||
import com.aizuda.easy.retry.common.core.model.IdempotentIdContext;
|
||||
|
||||
/**
|
||||
* 默认的idempotentId 生成器
|
||||
@ -13,7 +13,7 @@ import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||
public class SimpleIdempotentIdGenerate implements IdempotentIdGenerate {
|
||||
|
||||
@Override
|
||||
public String idGenerate(Object... t) throws Exception {
|
||||
return SecureUtil.md5(JsonUtil.toJsonString(t));
|
||||
public String idGenerate(IdempotentIdContext idempotentIdContext) throws Exception {
|
||||
return SecureUtil.md5(idempotentIdContext.toString());
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.easy.retry.client.core.retryer.RetryerInfo;
|
||||
import com.aizuda.easy.retry.client.core.spel.SPELParamFunction;
|
||||
import com.aizuda.easy.retry.common.core.log.LogUtils;
|
||||
import com.aizuda.easy.retry.common.core.model.IdempotentIdContext;
|
||||
import com.aizuda.easy.retry.server.model.dto.RetryTaskDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -71,9 +72,9 @@ public abstract class AbstractReport implements Report {
|
||||
try {
|
||||
Class<? extends IdempotentIdGenerate> idempotentIdGenerate = retryerInfo.getIdempotentIdGenerate();
|
||||
IdempotentIdGenerate generate = idempotentIdGenerate.newInstance();
|
||||
Method method = idempotentIdGenerate.getMethod("idGenerate", Object[].class);
|
||||
Object p = new Object[]{scene, targetClassName, args, executorMethod.getName()};
|
||||
idempotentId = (String) ReflectionUtils.invokeMethod(method, generate, p);
|
||||
Method method = idempotentIdGenerate.getMethod("idGenerate", IdempotentIdContext.class);
|
||||
IdempotentIdContext idempotentIdContext = new IdempotentIdContext(scene, targetClassName, args, executorMethod.getName());
|
||||
idempotentId = (String) ReflectionUtils.invokeMethod(method, generate, idempotentIdContext);
|
||||
} catch (Exception exception) {
|
||||
LogUtils.error(log, "幂等id生成异常:{},{}", scene, args, exception);
|
||||
throw new EasyRetryClientException("idempotentId生成异常:{},{}", scene, args);
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.aizuda.easy.retry.common.core.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class IdempotentIdContext {
|
||||
|
||||
private String scene;
|
||||
|
||||
private String targetClassName;
|
||||
|
||||
private Object[] args;
|
||||
|
||||
private String methodName;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user