feat:3.0.0
1. 修复回调执行器获取的错误问题 2. 修复Retryable作用在接口上无效问题 3. 修复多场景数据上报时重复生成retryTask
This commit is contained in:
parent
baa122cb56
commit
732c0c1cf0
@ -49,16 +49,16 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
|
|||||||
|
|
||||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
private static String retryErrorMoreThresholdTextMessageFormatter =
|
private static String retryErrorMoreThresholdTextMessageFormatter =
|
||||||
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试组件异常</font> \r\n" +
|
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试组件异常</font> \r\n" +
|
||||||
"> 名称:{} \r\n" +
|
"> 名称:{} \r\n" +
|
||||||
"> 时间:{} \r\n" +
|
"> 时间:{} \r\n" +
|
||||||
"> 异常:{} \n";
|
"> 异常:{} \n";
|
||||||
|
|
||||||
private final StandardEnvironment standardEnvironment;
|
private final StandardEnvironment standardEnvironment;
|
||||||
private final RetryStrategy retryStrategy;
|
private final RetryStrategy retryStrategy;
|
||||||
|
|
||||||
public EasyRetryInterceptor(StandardEnvironment standardEnvironment,
|
public EasyRetryInterceptor(StandardEnvironment standardEnvironment,
|
||||||
RetryStrategy localRetryStrategies) {
|
RetryStrategy localRetryStrategies) {
|
||||||
this.standardEnvironment = standardEnvironment;
|
this.standardEnvironment = standardEnvironment;
|
||||||
this.retryStrategy = localRetryStrategies;
|
this.retryStrategy = localRetryStrategies;
|
||||||
}
|
}
|
||||||
@ -86,10 +86,10 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
|
|||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
LogUtils.debug(log, "Start retrying. traceId:[{}] scene:[{}] executorClassName:[{}]", traceId,
|
LogUtils.debug(log, "Start retrying. traceId:[{}] scene:[{}] executorClassName:[{}]", traceId,
|
||||||
retryable.scene(), executorClassName);
|
retryable.scene(), executorClassName);
|
||||||
// 入口则开始处理重试
|
// 入口则开始处理重试
|
||||||
retryerResultContext = doHandlerRetry(invocation, traceId, retryable, executorClassName, methodEntrance,
|
retryerResultContext = doHandlerRetry(invocation, traceId, retryable, executorClassName, methodEntrance,
|
||||||
throwable);
|
throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogUtils.debug(log, "Method return value is [{}]. traceId:[{}]", result, traceId, throwable);
|
LogUtils.debug(log, "Method return value is [{}]. traceId:[{}]", result, traceId, throwable);
|
||||||
@ -98,8 +98,8 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
|
|||||||
if (Objects.nonNull(retryerResultContext)) {
|
if (Objects.nonNull(retryerResultContext)) {
|
||||||
// 重试成功直接返回结果 若注解配置了isThrowException=false 则不抛出异常
|
// 重试成功直接返回结果 若注解配置了isThrowException=false 则不抛出异常
|
||||||
if (retryerResultContext.getRetryResultStatusEnum().getStatus()
|
if (retryerResultContext.getRetryResultStatusEnum().getStatus()
|
||||||
.equals(RetryResultStatusEnum.SUCCESS.getStatus())
|
.equals(RetryResultStatusEnum.SUCCESS.getStatus())
|
||||||
|| !retryable.isThrowException()) {
|
|| !retryable.isThrowException()) {
|
||||||
|
|
||||||
// 若返回值是NULL且是基本类型则返回默认值
|
// 若返回值是NULL且是基本类型则返回默认值
|
||||||
Method method = invocation.getMethod();
|
Method method = invocation.getMethod();
|
||||||
@ -121,32 +121,32 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
|
|||||||
|
|
||||||
|
|
||||||
private RetryerResultContext doHandlerRetry(MethodInvocation invocation, String traceId, Retryable retryable,
|
private RetryerResultContext doHandlerRetry(MethodInvocation invocation, String traceId, Retryable retryable,
|
||||||
String executorClassName, String methodEntrance, Throwable throwable) {
|
String executorClassName, String methodEntrance, Throwable throwable) {
|
||||||
|
|
||||||
if (!RetrySiteSnapshot.isMethodEntrance(methodEntrance)
|
if (!RetrySiteSnapshot.isMethodEntrance(methodEntrance)
|
||||||
|| RetrySiteSnapshot.isRunning()
|
|| RetrySiteSnapshot.isRunning()
|
||||||
|| Objects.isNull(throwable)
|
|| Objects.isNull(throwable)
|
||||||
// 重试流量不开启重试
|
// 重试流量不开启重试
|
||||||
|| RetrySiteSnapshot.isRetryFlow()
|
|| RetrySiteSnapshot.isRetryFlow()
|
||||||
// 下游响应不重试码,不开启重试
|
// 下游响应不重试码,不开启重试
|
||||||
|| RetrySiteSnapshot.isRetryForStatusCode()
|
|| RetrySiteSnapshot.isRetryForStatusCode()
|
||||||
// 匹配异常信息
|
// 匹配异常信息
|
||||||
|| !validate(throwable, RetryerInfoCache.get(retryable.scene(), executorClassName))
|
|| !validate(throwable, RetryerInfoCache.get(retryable.scene(), executorClassName))
|
||||||
) {
|
) {
|
||||||
if (!RetrySiteSnapshot.isMethodEntrance(methodEntrance)) {
|
if (!RetrySiteSnapshot.isMethodEntrance(methodEntrance)) {
|
||||||
LogUtils.debug(log, "Non-method entry does not enable local retries. traceId:[{}] [{}]", traceId,
|
LogUtils.debug(log, "Non-method entry does not enable local retries. traceId:[{}] [{}]", traceId,
|
||||||
RetrySiteSnapshot.getMethodEntrance());
|
RetrySiteSnapshot.getMethodEntrance());
|
||||||
} else if (RetrySiteSnapshot.isRunning()) {
|
} else if (RetrySiteSnapshot.isRunning()) {
|
||||||
LogUtils.debug(log, "Existing running retry tasks do not enable local retries. traceId:[{}] [{}]",
|
LogUtils.debug(log, "Existing running retry tasks do not enable local retries. traceId:[{}] [{}]",
|
||||||
traceId, EnumStage.valueOfStage(RetrySiteSnapshot.getStage()));
|
traceId, EnumStage.valueOfStage(RetrySiteSnapshot.getStage()));
|
||||||
} else if (Objects.isNull(throwable)) {
|
} else if (Objects.isNull(throwable)) {
|
||||||
LogUtils.debug(log, "No exception, no local retries. traceId:[{}]", traceId);
|
LogUtils.debug(log, "No exception, no local retries. traceId:[{}]", traceId);
|
||||||
} else if (RetrySiteSnapshot.isRetryFlow()) {
|
} else if (RetrySiteSnapshot.isRetryFlow()) {
|
||||||
LogUtils.debug(log, "Retry traffic does not enable local retries. traceId:[{}] [{}]", traceId,
|
LogUtils.debug(log, "Retry traffic does not enable local retries. traceId:[{}] [{}]", traceId,
|
||||||
RetrySiteSnapshot.getRetryHeader());
|
RetrySiteSnapshot.getRetryHeader());
|
||||||
} else if (RetrySiteSnapshot.isRetryForStatusCode()) {
|
} else if (RetrySiteSnapshot.isRetryForStatusCode()) {
|
||||||
LogUtils.debug(log, "Existing exception retry codes do not enable local retries. traceId:[{}]",
|
LogUtils.debug(log, "Existing exception retry codes do not enable local retries. traceId:[{}]",
|
||||||
traceId);
|
traceId);
|
||||||
} else if (!validate(throwable, RetryerInfoCache.get(retryable.scene(), executorClassName))) {
|
} else if (!validate(throwable, RetryerInfoCache.get(retryable.scene(), executorClassName))) {
|
||||||
LogUtils.debug(log, "Exception mismatch. traceId:[{}]", traceId);
|
LogUtils.debug(log, "Exception mismatch. traceId:[{}]", traceId);
|
||||||
} else {
|
} else {
|
||||||
@ -159,7 +159,7 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RetryerResultContext openRetry(MethodInvocation point, String traceId, Retryable retryable,
|
private RetryerResultContext openRetry(MethodInvocation point, String traceId, Retryable retryable,
|
||||||
String executorClassName, Throwable throwable) {
|
String executorClassName, Throwable throwable) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
|
|||||||
initHeaders(retryable);
|
initHeaders(retryable);
|
||||||
|
|
||||||
RetryerResultContext context = retryStrategy.openRetry(retryable.scene(), executorClassName,
|
RetryerResultContext context = retryStrategy.openRetry(retryable.scene(), executorClassName,
|
||||||
point.getArguments());
|
point.getArguments());
|
||||||
if (RetryResultStatusEnum.SUCCESS.getStatus().equals(context.getRetryResultStatusEnum().getStatus())) {
|
if (RetryResultStatusEnum.SUCCESS.getStatus().equals(context.getRetryResultStatusEnum().getStatus())) {
|
||||||
LogUtils.debug(log, "local retry successful. traceId:[{}] result:[{}]", traceId, context.getResult());
|
LogUtils.debug(log, "local retry successful. traceId:[{}] result:[{}]", traceId, context.getResult());
|
||||||
} else {
|
} else {
|
||||||
@ -201,16 +201,16 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ConfigDTO.Notify notifyAttribute = GroupVersionCache.getNotifyAttribute(
|
ConfigDTO.Notify notifyAttribute = GroupVersionCache.getNotifyAttribute(
|
||||||
NotifySceneEnum.CLIENT_COMPONENT_ERROR.getNotifyScene());
|
NotifySceneEnum.CLIENT_COMPONENT_ERROR.getNotifyScene());
|
||||||
if (Objects.nonNull(notifyAttribute)) {
|
if (Objects.nonNull(notifyAttribute)) {
|
||||||
AlarmContext context = AlarmContext.build()
|
AlarmContext context = AlarmContext.build()
|
||||||
.text(retryErrorMoreThresholdTextMessageFormatter,
|
.text(retryErrorMoreThresholdTextMessageFormatter,
|
||||||
EnvironmentUtils.getActiveProfile(),
|
EnvironmentUtils.getActiveProfile(),
|
||||||
EasyRetryProperties.getGroup(),
|
EasyRetryProperties.getGroup(),
|
||||||
LocalDateTime.now().format(formatter),
|
LocalDateTime.now().format(formatter),
|
||||||
e.getMessage())
|
e.getMessage())
|
||||||
.title("retry component handling exception:[{}]", EasyRetryProperties.getGroup())
|
.title("retry component handling exception:[{}]", EasyRetryProperties.getGroup())
|
||||||
.notifyAttribute(notifyAttribute.getNotifyAttribute());
|
.notifyAttribute(notifyAttribute.getNotifyAttribute());
|
||||||
|
|
||||||
Alarm<AlarmContext> alarmType = SpringContext.getBeanByType(EasyRetryAlarmFactory.class).getAlarmType(notifyAttribute.getNotifyType());
|
Alarm<AlarmContext> alarmType = SpringContext.getBeanByType(EasyRetryAlarmFactory.class).getAlarmType(notifyAttribute.getNotifyType());
|
||||||
alarmType.asyncSendMessage(context);
|
alarmType.asyncSendMessage(context);
|
||||||
@ -249,7 +249,7 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
|
|||||||
@Override
|
@Override
|
||||||
public int getOrder() {
|
public int getOrder() {
|
||||||
String order = standardEnvironment
|
String order = standardEnvironment
|
||||||
.getProperty("easy-retry.aop.order", String.valueOf(Ordered.HIGHEST_PRECEDENCE));
|
.getProperty("easy-retry.aop.order", String.valueOf(Ordered.HIGHEST_PRECEDENCE));
|
||||||
return Integer.parseInt(order);
|
return Integer.parseInt(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user