feat: 2.2.0

1. 优化日志信息
2. 修复远程重试返回值为基本类型时返回异常
This commit is contained in:
byteblogs168 2023-08-25 15:34:12 +08:00
parent 63761cd225
commit a9058d8ca6
4 changed files with 24 additions and 7 deletions

View File

@ -20,6 +20,7 @@ import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.common.core.model.EasyRetryHeaders;
import com.aizuda.easy.retry.common.core.util.EnvironmentUtils;
import com.aizuda.easy.retry.server.model.dto.ConfigDTO;
import com.google.common.base.Defaults;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@ -97,6 +98,13 @@ public class RetryAspect implements Ordered {
// 重试成功直接返回结果 若注解配置了isThrowException=false 则不抛出异常
if (retryerResultContext.getRetryResultStatusEnum().getStatus().equals(RetryResultStatusEnum.SUCCESS.getStatus())
|| !retryable.isThrowException()) {
// 若返回值是NULL且是基本类型则返回默认值
MethodSignature signature = (MethodSignature) point.getSignature();
if (Objects.isNull(retryerResultContext.getResult()) && signature.getReturnType().isPrimitive()) {
return Defaults.defaultValue(signature.getReturnType());
}
return retryerResultContext.getResult();
}
}

View File

@ -92,7 +92,7 @@ public class ReportListener implements Listener<RetryTaskDTO> {
public <V> void onRetry(Attempt<V> attempt) {
if (attempt.hasException()) {
LogUtils.error(log,"easy-retry 上报服务端失败,第[{}]次尝试上报 ", attempt.getAttemptNumber(), attempt.getExceptionCause());
LogUtils.error(log,"EasyRetry上报异常数据时接口发生异常,第[{}]次尝试上报 ", attempt.getAttemptNumber(), attempt.getExceptionCause());
}
}

View File

@ -7,17 +7,18 @@ package com.aizuda.easy.retry.client.core.retryer;
public enum RetryType {
/**
* 本地重试
* 本地重试: 发生异常时通过内存进行重试
*/
ONLY_LOCAL,
/**
* 远程重试
* 远程重试: 发生异常时将数据上报到服务端进行重试
*/
ONLY_REMOTE,
/**
* 先本地重试在远程重试
* 现在本地进行内存重试N次如果本地重试未解决将异常数据上报到服务端进行重试
*/
LOCAL_REMOTE
}

View File

@ -53,7 +53,15 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
@Override
protected Consumer<Object> doRetrySuccessConsumer(RetryerResultContext context) {
return o -> {
LogUtils.debug(log, "doRetrySuccessConsumer 重试成功");
RetryerInfo retryerInfo = context.getRetryerInfo();
if (retryerInfo.getRetryType() == RetryType.ONLY_REMOTE) {
// 若是远程重试模式采用直接上报服务端
// 这里标志结果为失败是表示数据并未重试成功等待服务端重试
context.setRetryResultStatusEnum(RetryResultStatusEnum.FAILURE);
} else {
LogUtils.debug(log, "doRetrySuccessConsumer 重试成功");
}
};
}
@ -157,7 +165,7 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
LogUtils.error(log,"[{}] 执行本地重试失败,第[{}]次重试", retryerInfo.getScene(), attempt.getAttemptNumber());
break;
case ONLY_REMOTE:
LogUtils.error(log,"[{}] 执行远程重试失败,第[{}]次重试", retryerInfo.getScene(), attempt.getAttemptNumber());
LogUtils.error(log,"[{}] 执行上报服务端失败,第[{}]次重试", retryerInfo.getScene(), attempt.getAttemptNumber());
break;
default:
throw new EasyRetryClientException("异常重试模式 [{}]", retryType.name());
@ -168,10 +176,10 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
switch (retryType) {
case ONLY_LOCAL:
case LOCAL_REMOTE:
LogUtils.info(log,"[{}] 执行本地重试成功.", retryerInfo.getScene(), attempt.getAttemptNumber());
LogUtils.info(log,"[{}] 执行本地重试成功.", retryerInfo.getScene());
break;
case ONLY_REMOTE:
LogUtils.info(log,"[{}] 执行远程成功.", retryerInfo.getScene(), attempt.getAttemptNumber());
LogUtils.info(log,"[{}] 执行上报服务端成功.", retryerInfo.getScene());
break;
default:
throw new EasyRetryClientException("异常重试模式 [{}]", retryType.name());