feat: 2.1.0

1. 优化上报和超时异常日志
This commit is contained in:
byteblogs168 2023-07-29 12:09:46 +08:00
parent 17c0267661
commit 44ba9c744b
4 changed files with 54 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import com.aizuda.easy.retry.client.core.annotation.Mapping;
import com.aizuda.easy.retry.client.core.client.netty.NettyChannel;
import com.aizuda.easy.retry.client.core.client.netty.RpcContext;
import com.aizuda.easy.retry.client.core.exception.EasyRetryClientException;
import com.aizuda.easy.retry.client.core.exception.EasyRetryClientTimeOutException;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.common.core.model.EasyRetryRequest;
import com.aizuda.easy.retry.common.core.util.JsonUtil;
@ -15,7 +16,9 @@ import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
/**
@ -41,7 +44,7 @@ public class ClientInvokeHandler<R> implements InvocationHandler {
}
@Override
public R invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
public R invoke(final Object proxy, final Method method, final Object[] args) throws InterruptedException {
StopWatch sw = new StopWatch();
Mapping annotation = method.getAnnotation(Mapping.class);
EasyRetryRequest easyRetryRequest = new EasyRetryRequest(args);
@ -67,7 +70,13 @@ public class ClientInvokeHandler<R> implements InvocationHandler {
return null;
} else {
Assert.notNull(completableFuture, () -> new EasyRetryClientException("completableFuture is null"));
return completableFuture.get(timeout, unit);
try {
return completableFuture.get(timeout, unit);
} catch (ExecutionException e) {
throw new EasyRetryClientException("Request to remote interface exception. path:[{}]", annotation.path());
} catch (TimeoutException e) {
throw new EasyRetryClientTimeOutException("Request to remote interface timed out. path:[{}]", annotation.path());
}
}
}

View File

@ -0,0 +1,38 @@
package com.aizuda.easy.retry.client.core.exception;
import com.aizuda.easy.retry.common.core.exception.BaseEasyRetryException;
/**
* @author: www.byteblogs.com
* @date : 2022-03-03 14:49
*/
public class EasyRetryClientTimeOutException extends BaseEasyRetryException {
public EasyRetryClientTimeOutException(String message) {
super(message);
}
public EasyRetryClientTimeOutException(String message, Throwable cause) {
super(message, cause);
}
public EasyRetryClientTimeOutException(Throwable cause) {
super(cause);
}
public EasyRetryClientTimeOutException(String message, Object... arguments) {
super(message, arguments);
}
public EasyRetryClientTimeOutException(String message, Object[] arguments, Throwable cause) {
super(message, arguments, cause);
}
public EasyRetryClientTimeOutException(String message, Object argument, Throwable cause) {
super(message, argument, cause);
}
public EasyRetryClientTimeOutException(String message, Object argument) {
super(message, argument);
}
}

View File

@ -64,9 +64,9 @@ public abstract class AbstractRetryStrategies implements RetryStrategy {
retryerResultContext.setResult(result);
} catch (Exception e) {
log.error("重试执行非预期异常", e);
log.error("重试期间发生非预期异常, sceneName:[{}] executorClassName:[{}]", sceneName, executorClassName, e);
retryerResultContext.setMessage("非预期异常" + e.getMessage());
// 本地重试状态失败 远程重试状态为成功
// 本地重试状态失败 远程重试状态为成功
unexpectedError(e, retryerResultContext);
}

View File

@ -120,11 +120,9 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
case ONLY_REMOTE:
// 仅仅是远程重试则直接上报
log.debug("上报 scene:[{}]", retryerInfo.getScene());
return () -> {
doReport(retryerInfo, params);
RetrySiteSnapshot.setStage(RetrySiteSnapshot.EnumStage.REMOTE.getStage());
return null;
};
doReport(retryerInfo, params);
RetrySiteSnapshot.setStage(RetrySiteSnapshot.EnumStage.REMOTE.getStage());
return () -> null;
default:
throw new EasyRetryClientException("异常重试模式 [{}]", retryType.name());
}