feat: 1.5.0
1. 本地重试添加重试流量标识
This commit is contained in:
parent
7c6eb9ebdf
commit
f84eaf7e23
@ -3,13 +3,16 @@ package com.aizuda.easy.retry.client.core.cache;
|
||||
import com.aizuda.easy.retry.client.core.Lifecycle;
|
||||
import com.aizuda.easy.retry.client.core.client.NettyClient;
|
||||
import com.aizuda.easy.retry.client.core.client.proxy.RequestBuilder;
|
||||
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
||||
import com.aizuda.easy.retry.common.core.log.LogUtils;
|
||||
import com.aizuda.easy.retry.common.core.model.NettyResult;
|
||||
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||
import com.aizuda.easy.retry.server.model.dto.ConfigDTO;
|
||||
import com.aizuda.easy.retry.server.model.dto.ConfigDTO.Scene;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -34,6 +37,21 @@ public class GroupVersionCache implements Lifecycle {
|
||||
return configDTO.getVersion();
|
||||
}
|
||||
|
||||
public static long getDdl(String sceneName) {
|
||||
List<Scene> sceneList = configDTO.getSceneList();
|
||||
if (CollectionUtils.isEmpty(sceneList)) {
|
||||
return SystemConstants.DEFAULT_DDL;
|
||||
}
|
||||
|
||||
for (Scene scene : sceneList) {
|
||||
if (scene.getSceneName().equals(sceneName)) {
|
||||
return scene.getDdl();
|
||||
}
|
||||
}
|
||||
|
||||
return SystemConstants.DEFAULT_DDL;
|
||||
}
|
||||
|
||||
public static Set<String> getSceneBlacklist() {
|
||||
if (Objects.isNull(configDTO)) {
|
||||
return new HashSet<>();
|
||||
|
@ -1,5 +1,6 @@
|
||||
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.config.EasyRetryProperties;
|
||||
@ -11,10 +12,13 @@ import com.aizuda.easy.retry.client.core.retryer.RetryerResultContext;
|
||||
import com.aizuda.easy.retry.common.core.alarm.Alarm;
|
||||
import com.aizuda.easy.retry.common.core.alarm.AlarmContext;
|
||||
import com.aizuda.easy.retry.common.core.alarm.AltinAlarmFactory;
|
||||
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
||||
import com.aizuda.easy.retry.common.core.enums.NotifySceneEnum;
|
||||
import com.aizuda.easy.retry.common.core.enums.RetryResultStatusEnum;
|
||||
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.common.core.util.JsonUtil;
|
||||
import com.aizuda.easy.retry.server.model.dto.ConfigDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
@ -136,6 +140,9 @@ public class RetryAspect implements Ordered {
|
||||
|
||||
try {
|
||||
|
||||
// 标识重试流量
|
||||
initHeaders(retryable);
|
||||
|
||||
RetryerResultContext context = retryStrategy.openRetry(retryable.scene(), executorClassName, point.getArgs());
|
||||
LogUtils.info(log,"local retry result. traceId:[{}] message:[{}]", traceId, context);
|
||||
if (RetryResultStatusEnum.SUCCESS.getStatus().equals(context.getRetryResultStatusEnum().getStatus())) {
|
||||
@ -156,6 +163,15 @@ public class RetryAspect implements Ordered {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void initHeaders(final Retryable retryable) {
|
||||
|
||||
EasyRetryHeaders easyRetryHeaders = new EasyRetryHeaders();
|
||||
easyRetryHeaders.setEasyRetry(Boolean.TRUE);
|
||||
easyRetryHeaders.setEasyRetryId(IdUtil.getSnowflakeNextIdStr());
|
||||
easyRetryHeaders.setDdl(GroupVersionCache.getDdl(retryable.scene()));
|
||||
RetrySiteSnapshot.setRetryHeader(easyRetryHeaders);
|
||||
}
|
||||
|
||||
private void sendMessage(Exception e) {
|
||||
|
||||
try {
|
||||
|
@ -148,7 +148,7 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
|
||||
return Collections.singletonList(new RetryListener() {
|
||||
@Override
|
||||
public <V> void onRetry(Attempt<V> attempt) {
|
||||
LogUtils.error(log,"easy-retry 本地重试,第[{}]次调度", attempt.getAttemptNumber());
|
||||
LogUtils.info(log,"easy-retry 本地重试,第[{}]次调度", attempt.getAttemptNumber());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public class ManualRetryStrategies extends AbstractRetryStrategies {
|
||||
@Override
|
||||
public <V> void onRetry(Attempt<V> attempt) {
|
||||
if (attempt.hasResult()) {
|
||||
LogUtils.error(log, "easy-retry 手动创建重试数据成功,第[{}]次调度", attempt.getAttemptNumber());
|
||||
LogUtils.info(log, "easy-retry 手动创建重试数据成功,第[{}]次调度", attempt.getAttemptNumber());
|
||||
}
|
||||
|
||||
if (attempt.hasException()) {
|
||||
|
@ -24,6 +24,11 @@ public interface SystemConstants {
|
||||
*/
|
||||
String EASY_RETRY_STATUS_CODE = "519";
|
||||
|
||||
/**
|
||||
* 默认的调用链超时时间 单位毫秒(ms)
|
||||
*/
|
||||
long DEFAULT_DDL = 60000L;
|
||||
|
||||
/**
|
||||
* 心跳
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.aizuda.easy.retry.common.core.model;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@ -24,5 +25,5 @@ public class EasyRetryHeaders {
|
||||
/**
|
||||
* 调用链超时时间 单位毫秒(ms)
|
||||
*/
|
||||
private long ddl = 60000;
|
||||
private long ddl = SystemConstants.DEFAULT_DDL;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.aizuda.easy.retry.server.model.dto;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
||||
import com.aizuda.easy.retry.common.core.enums.AlarmTypeEnum;
|
||||
import com.aizuda.easy.retry.common.core.enums.NotifySceneEnum;
|
||||
import lombok.Data;
|
||||
@ -37,6 +38,16 @@ public class ConfigDTO {
|
||||
|
||||
@Data
|
||||
public static class Scene {
|
||||
|
||||
/**
|
||||
* 场景名称
|
||||
*/
|
||||
private String sceneName;
|
||||
|
||||
/**
|
||||
* 调用链超时时间 单位毫秒(ms)
|
||||
*/
|
||||
private long ddl = SystemConstants.DEFAULT_DDL;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
@ -53,10 +53,18 @@ public interface ConfigAccess {
|
||||
* 获取通知配置
|
||||
*
|
||||
* @param groupName 组名称
|
||||
* @return {@link NotifyConfig} 场景配置
|
||||
* @return {@link NotifyConfig} 通知配置
|
||||
*/
|
||||
List<NotifyConfig> getNotifyListConfigByGroupName(String groupName);
|
||||
|
||||
/**
|
||||
* 获取场景配置
|
||||
*
|
||||
* @param groupName 组名称
|
||||
* @return {@link SceneConfig} 场景配置
|
||||
*/
|
||||
List<SceneConfig> getSceneConfigByGroupName(String groupName);
|
||||
|
||||
/**
|
||||
* 获取已开启的组配置信息
|
||||
*
|
||||
|
@ -38,6 +38,11 @@ public abstract class AbstractConfigAccess implements ConfigAccess {
|
||||
.eq(SceneConfig::getGroupName, groupName).eq(SceneConfig::getSceneName, sceneName));
|
||||
}
|
||||
|
||||
protected List<SceneConfig> getSceneConfigs(String groupName) {
|
||||
return sceneConfigMapper.selectList(new LambdaQueryWrapper<SceneConfig>()
|
||||
.eq(SceneConfig::getGroupName, groupName));
|
||||
}
|
||||
|
||||
protected GroupConfig getByGroupName(String groupName) {
|
||||
return groupConfigMapper.selectOne(new LambdaQueryWrapper<GroupConfig>().eq(GroupConfig::getGroupName, groupName));
|
||||
}
|
||||
|
@ -48,6 +48,11 @@ public class MybatisConfigAccess extends AbstractConfigAccess {
|
||||
return getNotifyConfigs(shardingGroupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SceneConfig> getSceneConfigByGroupName(String groupName) {
|
||||
return getSceneConfigs(groupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GroupConfig> getAllOpenGroupConfig() {
|
||||
return getAllConfigGroupList().stream().filter(i-> StatusEnum.YES.getStatus().equals(i.getGroupStatus())).collect(Collectors.toList());
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.aizuda.easy.retry.server.persistence.support.processor;
|
||||
|
||||
import com.aizuda.easy.retry.server.model.dto.ConfigDTO;
|
||||
import com.aizuda.easy.retry.server.model.dto.ConfigDTO.Scene;
|
||||
import com.aizuda.easy.retry.server.persistence.mybatis.po.GroupConfig;
|
||||
import com.aizuda.easy.retry.server.persistence.mybatis.po.NotifyConfig;
|
||||
import com.aizuda.easy.retry.server.persistence.mybatis.po.SceneConfig;
|
||||
@ -55,6 +56,11 @@ public class ConfigAccessProcessor implements ConfigAccess {
|
||||
return configAccess.getNotifyListConfigByGroupName(groupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SceneConfig> getSceneConfigByGroupName(final String groupName) {
|
||||
return configAccess.getSceneConfigByGroupName(groupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GroupConfig> getAllOpenGroupConfig() {
|
||||
return configAccess.getAllOpenGroupConfig();
|
||||
@ -107,6 +113,18 @@ public class ConfigAccessProcessor implements ConfigAccess {
|
||||
}
|
||||
|
||||
configDTO.setNotifyList(notifies);
|
||||
|
||||
List<SceneConfig> sceneConfig = getSceneConfigByGroupName(groupName);
|
||||
|
||||
List<Scene> sceneList = new ArrayList<>();
|
||||
for (SceneConfig config : sceneConfig) {
|
||||
Scene scene = new Scene();
|
||||
scene.setSceneName(config.getSceneName());
|
||||
scene.setDdl(config.getDeadlineRequest());
|
||||
sceneList.add(scene);
|
||||
}
|
||||
|
||||
configDTO.setSceneList(sceneList);
|
||||
return configDTO;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.aizuda.easy.retry.server.web.model.request;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
||||
import com.aizuda.easy.retry.server.enums.IdGeneratorMode;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
@ -120,7 +121,7 @@ public class GroupConfigRequestVO {
|
||||
* Deadline Request 调用链超时 单位毫秒
|
||||
* 默认值为 60*10*1000
|
||||
*/
|
||||
@Max(message = "最大60000毫秒", value = 60000)
|
||||
@Max(message = "最大60000毫秒", value = SystemConstants.DEFAULT_DDL)
|
||||
@Min(message = "最小100ms", value = 100)
|
||||
private Long deadlineRequest;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user