feat: 2.2.0
1. 优化日志信息 2. 修复远程重试返回值为基本类型时返回异常
This commit is contained in:
parent
63761cd225
commit
a9058d8ca6
@ -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.model.EasyRetryHeaders;
|
||||||
import com.aizuda.easy.retry.common.core.util.EnvironmentUtils;
|
import com.aizuda.easy.retry.common.core.util.EnvironmentUtils;
|
||||||
import com.aizuda.easy.retry.server.model.dto.ConfigDTO;
|
import com.aizuda.easy.retry.server.model.dto.ConfigDTO;
|
||||||
|
import com.google.common.base.Defaults;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
@ -97,6 +98,13 @@ public class RetryAspect implements Ordered {
|
|||||||
// 重试成功直接返回结果 若注解配置了isThrowException=false 则不抛出异常
|
// 重试成功直接返回结果 若注解配置了isThrowException=false 则不抛出异常
|
||||||
if (retryerResultContext.getRetryResultStatusEnum().getStatus().equals(RetryResultStatusEnum.SUCCESS.getStatus())
|
if (retryerResultContext.getRetryResultStatusEnum().getStatus().equals(RetryResultStatusEnum.SUCCESS.getStatus())
|
||||||
|| !retryable.isThrowException()) {
|
|| !retryable.isThrowException()) {
|
||||||
|
|
||||||
|
// 若返回值是NULL且是基本类型则返回默认值
|
||||||
|
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||||
|
if (Objects.isNull(retryerResultContext.getResult()) && signature.getReturnType().isPrimitive()) {
|
||||||
|
return Defaults.defaultValue(signature.getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
return retryerResultContext.getResult();
|
return retryerResultContext.getResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class ReportListener implements Listener<RetryTaskDTO> {
|
|||||||
public <V> void onRetry(Attempt<V> attempt) {
|
public <V> void onRetry(Attempt<V> attempt) {
|
||||||
|
|
||||||
if (attempt.hasException()) {
|
if (attempt.hasException()) {
|
||||||
LogUtils.error(log,"easy-retry 上报服务端失败,第[{}]次尝试上报 ", attempt.getAttemptNumber(), attempt.getExceptionCause());
|
LogUtils.error(log,"EasyRetry上报异常数据时接口发生异常,第[{}]次尝试上报 ", attempt.getAttemptNumber(), attempt.getExceptionCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,17 +7,18 @@ package com.aizuda.easy.retry.client.core.retryer;
|
|||||||
public enum RetryType {
|
public enum RetryType {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地重试
|
* 本地重试: 发生异常时通过内存进行重试
|
||||||
*/
|
*/
|
||||||
ONLY_LOCAL,
|
ONLY_LOCAL,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程重试
|
* 远程重试: 发生异常时将数据上报到服务端进行重试
|
||||||
*/
|
*/
|
||||||
ONLY_REMOTE,
|
ONLY_REMOTE,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 先本地重试,在远程重试
|
* 先本地重试,在远程重试
|
||||||
|
* 即:现在本地进行内存重试N次,如果本地重试未解决,将异常数据上报到服务端进行重试
|
||||||
*/
|
*/
|
||||||
LOCAL_REMOTE
|
LOCAL_REMOTE
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,15 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
|
|||||||
@Override
|
@Override
|
||||||
protected Consumer<Object> doRetrySuccessConsumer(RetryerResultContext context) {
|
protected Consumer<Object> doRetrySuccessConsumer(RetryerResultContext context) {
|
||||||
return o -> {
|
return o -> {
|
||||||
|
|
||||||
|
RetryerInfo retryerInfo = context.getRetryerInfo();
|
||||||
|
if (retryerInfo.getRetryType() == RetryType.ONLY_REMOTE) {
|
||||||
|
// 若是远程重试模式,采用直接上报服务端
|
||||||
|
// 这里标志结果为失败,是表示数据并未重试成功,等待服务端重试
|
||||||
|
context.setRetryResultStatusEnum(RetryResultStatusEnum.FAILURE);
|
||||||
|
} else {
|
||||||
LogUtils.debug(log, "doRetrySuccessConsumer 重试成功");
|
LogUtils.debug(log, "doRetrySuccessConsumer 重试成功");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +165,7 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
|
|||||||
LogUtils.error(log,"[{}] 执行本地重试失败,第[{}]次重试", retryerInfo.getScene(), attempt.getAttemptNumber());
|
LogUtils.error(log,"[{}] 执行本地重试失败,第[{}]次重试", retryerInfo.getScene(), attempt.getAttemptNumber());
|
||||||
break;
|
break;
|
||||||
case ONLY_REMOTE:
|
case ONLY_REMOTE:
|
||||||
LogUtils.error(log,"[{}] 执行远程重试失败,第[{}]次重试", retryerInfo.getScene(), attempt.getAttemptNumber());
|
LogUtils.error(log,"[{}] 执行上报服务端失败,第[{}]次重试", retryerInfo.getScene(), attempt.getAttemptNumber());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new EasyRetryClientException("异常重试模式 [{}]", retryType.name());
|
throw new EasyRetryClientException("异常重试模式 [{}]", retryType.name());
|
||||||
@ -168,10 +176,10 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
|
|||||||
switch (retryType) {
|
switch (retryType) {
|
||||||
case ONLY_LOCAL:
|
case ONLY_LOCAL:
|
||||||
case LOCAL_REMOTE:
|
case LOCAL_REMOTE:
|
||||||
LogUtils.info(log,"[{}] 执行本地重试成功.", retryerInfo.getScene(), attempt.getAttemptNumber());
|
LogUtils.info(log,"[{}] 执行本地重试成功.", retryerInfo.getScene());
|
||||||
break;
|
break;
|
||||||
case ONLY_REMOTE:
|
case ONLY_REMOTE:
|
||||||
LogUtils.info(log,"[{}] 执行远程成功.", retryerInfo.getScene(), attempt.getAttemptNumber());
|
LogUtils.info(log,"[{}] 执行上报服务端成功.", retryerInfo.getScene());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new EasyRetryClientException("异常重试模式 [{}]", retryType.name());
|
throw new EasyRetryClientException("异常重试模式 [{}]", retryType.name());
|
||||||
|
Loading…
Reference in New Issue
Block a user