From 4e3aec94c24f5718da39e20a2c40b966c15847ae Mon Sep 17 00:00:00 2001 From: byteblogs168 <598092184@qq.com> Date: Tue, 20 Jun 2023 09:06:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=202.0.0=201.=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E9=87=8D=E8=AF=95=E6=B3=A8=E8=A7=A3=E4=B8=AD?= =?UTF-8?q?=E7=9A=84exclude=E5=92=8Cinclude=EF=BC=8C=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BA=86=E4=BB=8D=E7=84=B6=E6=89=A7=E8=A1=8C=E4=BA=862?= =?UTF-8?q?=E6=AC=A1=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/core/intercepter/RetryAspect.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/RetryAspect.java b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/RetryAspect.java index 81cc3ea9..8550816e 100644 --- a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/RetryAspect.java +++ b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/RetryAspect.java @@ -3,9 +3,11 @@ package com.aizuda.easy.retry.client.core.intercepter; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import com.aizuda.easy.retry.client.core.cache.GroupVersionCache; +import com.aizuda.easy.retry.client.core.cache.RetryerInfoCache; import com.aizuda.easy.retry.client.core.config.EasyRetryProperties; import com.aizuda.easy.retry.client.core.exception.EasyRetryClientException; import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot.EnumStage; +import com.aizuda.easy.retry.client.core.retryer.RetryerInfo; import com.aizuda.easy.retry.client.core.strategy.RetryStrategy; import com.aizuda.easy.retry.client.core.annotation.Retryable; import com.aizuda.easy.retry.client.core.retryer.RetryerResultContext; @@ -28,11 +30,13 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.Ordered; import org.springframework.core.env.StandardEnvironment; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; import java.lang.reflect.Method; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Objects; +import java.util.Set; import java.util.UUID; /** @@ -114,6 +118,8 @@ public class RetryAspect implements Ordered { || RetrySiteSnapshot.isRetryFlow() // 下游响应不重试码,不开启重试 || RetrySiteSnapshot.isRetryForStatusCode() + // 匹配异常信息 + || !validate(throwable, RetryerInfoCache.get(retryable.scene(), executorClassName)) ) { if (!RetrySiteSnapshot.isMethodEntrance(methodEntrance)) { LogUtils.debug(log, "Non-method entry does not enable local retries. traceId:[{}] [{}]", traceId, RetrySiteSnapshot.getMethodEntrance()); @@ -125,6 +131,8 @@ public class RetryAspect implements Ordered { LogUtils.debug(log, "Retry traffic does not enable local retries. traceId:[{}] [{}]", traceId, RetrySiteSnapshot.getRetryHeader()); } else if (RetrySiteSnapshot.isRetryForStatusCode()) { LogUtils.debug(log, "Existing exception retry codes do not enable local retries. traceId:[{}]", traceId); + } else if(!validate(throwable, RetryerInfoCache.get(retryable.scene(), executorClassName))) { + LogUtils.debug(log, "Exception mismatch. traceId:[{}]", traceId); } else { LogUtils.debug(log, "Unknown situations do not enable local retry scenarios. traceId:[{}]", traceId); } @@ -221,4 +229,32 @@ public class RetryAspect implements Ordered { .getProperty("easy-retry.aop.order", String.valueOf(Ordered.HIGHEST_PRECEDENCE)); return Integer.parseInt(order); } + + private boolean validate(Throwable throwable, RetryerInfo retryerInfo) { + + Set> exclude = retryerInfo.getExclude(); + Set> include = retryerInfo.getInclude(); + + if (CollectionUtils.isEmpty(include) && CollectionUtils.isEmpty(exclude)) { + return true; + } + + for (Class e : include) { + if (e.isAssignableFrom(throwable.getClass())) { + return true; + } + } + + if (!CollectionUtils.isEmpty(exclude)) { + for (Class e : exclude) { + if (e.isAssignableFrom(throwable.getClass())) { + return false; + } + } + + return true; + } + + return false; + } }