From 808bcfe0be4a1b761717771b93cda061d5f57fc2 Mon Sep 17 00:00:00 2001 From: "www.byteblogs.com" <598092184@qq.com> Date: Wed, 28 Jun 2023 23:46:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=202.0.0=201.=20=E4=BC=98=E5=8C=96Idempote?= =?UTF-8?q?ntIdContext=E6=B3=A8=E9=87=8A=202.=20=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=B9=82=E7=AD=89=E5=8F=B7=E6=94=B9=E4=B8=BA?= =?UTF-8?q?IdempotentIdContext=E4=BC=A0=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/core/IdempotentIdGenerate.java | 4 ++-- .../client/core/client/RetryEndPoint.java | 7 ++++--- .../generator/SimpleIdempotentIdGenerate.java | 4 ++-- .../core/model/IdempotentIdContext.java | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 7 deletions(-) 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 362144c7d..2ce4ca501 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 @@ -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; } diff --git a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java index f51a0102f..a6a77ab37 100644 --- a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java +++ b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java @@ -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 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); 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 ba9840b89..ada56a945 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 @@ -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()); } } 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 index 36467338d..695f19cf7 100644 --- 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 @@ -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; }