diff --git a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/IdempotentIdGenerate.java b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/IdempotentIdGenerate.java index b78572937..362144c7d 100644 --- a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/IdempotentIdGenerate.java +++ b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/IdempotentIdGenerate.java @@ -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; } diff --git a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/generator/SimpleIdempotentIdGenerate.java b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/generator/SimpleIdempotentIdGenerate.java index 78c2c3a9a..ba9840b89 100644 --- a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/generator/SimpleIdempotentIdGenerate.java +++ b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/generator/SimpleIdempotentIdGenerate.java @@ -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()); } } diff --git a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/report/AbstractReport.java b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/report/AbstractReport.java index 6211c520f..936f4150b 100644 --- a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/report/AbstractReport.java +++ b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/report/AbstractReport.java @@ -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 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); diff --git a/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/model/IdempotentIdContext.java b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/model/IdempotentIdContext.java new file mode 100644 index 000000000..36467338d --- /dev/null +++ b/easy-retry-common/easy-retry-common-core/src/main/java/com/aizuda/easy/retry/common/core/model/IdempotentIdContext.java @@ -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; + +}