feat: 2.2.0

1. 优化数据处理模板
2. 优化客户端日志
This commit is contained in:
byteblogs168 2023-08-28 16:56:02 +08:00
parent 68f9e77a92
commit 1ad33bff6c
6 changed files with 39 additions and 58 deletions

View File

@ -9,6 +9,7 @@ import com.aizuda.easy.retry.common.core.model.EasyRetryHeaders;
import lombok.Getter;
import java.util.Objects;
import java.util.Optional;
/**
* 重试现场记录器
@ -31,7 +32,7 @@ public class RetrySiteSnapshot {
/**
* 重试状态
*/
private static final RetrySiteSnapshotContext<Integer> RETRY_STATUS = EasyRetrySpiLoader.loadRetrySiteSnapshotContext(new ThreadLockRetrySiteSnapshotContext<>(ThreadLocal.withInitial(EnumStatus.COMPLETE::getStatus)));
private static final RetrySiteSnapshotContext<Integer> RETRY_STATUS = EasyRetrySpiLoader.loadRetrySiteSnapshotContext();
/**
* 重试请求头
@ -77,7 +78,8 @@ public class RetrySiteSnapshot {
}
public static Integer getStatus() {
return RETRY_STATUS.get();
return Optional.ofNullable(RETRY_STATUS.get()).orElse(EnumStatus.COMPLETE.status);
}
public static void setStatus(Integer status) {

View File

@ -52,16 +52,7 @@ public class EasyRetrySpiLoader {
/**
* 加载重试现场记录上下文SPI类
*
* @return {@link SimpleEasyRetryListener} 默认序列化类为SimpleEasyRetryListener
*/
public static <T> RetrySiteSnapshotContext<T> loadRetrySiteSnapshotContext(RetrySiteSnapshotContext<T> context) {
return Optional.ofNullable(ServiceLoaderUtil.loadFirst(RetrySiteSnapshotContext.class)).orElse(context);
}
/**
* 加载重试现场记录上下文SPI类
*
* @return {@link SimpleEasyRetryListener} 默认序列化类为SimpleEasyRetryListener
* @return {@link RetrySiteSnapshotContext} 默认序列化类为ThreadLockRetrySiteSnapshotContext
*/
public static <T> RetrySiteSnapshotContext<T> loadRetrySiteSnapshotContext() {
return Optional.ofNullable(ServiceLoaderUtil.loadFirst(RetrySiteSnapshotContext.class)).orElse(new ThreadLockRetrySiteSnapshotContext<T>(new ThreadLocal<>()));

View File

@ -7,6 +7,7 @@ import com.aizuda.easy.retry.client.core.config.EasyRetryProperties;
import com.aizuda.easy.retry.client.core.event.EasyRetryListener;
import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot;
import com.aizuda.easy.retry.client.core.Report;
import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot.EnumStatus;
import com.aizuda.easy.retry.client.core.loader.EasyRetrySpiLoader;
import com.aizuda.easy.retry.common.core.alarm.Alarm;
import com.aizuda.easy.retry.common.core.alarm.AlarmContext;
@ -90,6 +91,9 @@ public abstract class AbstractRetryStrategies implements RetryStrategy {
// 预警
sendMessage(e);
} finally {
// 重试调度完成
RetrySiteSnapshot.setStatus(EnumStatus.COMPLETE.getStatus());
}
return retryerResultContext;
@ -132,8 +136,6 @@ public abstract class AbstractRetryStrategies implements RetryStrategy {
} catch (Exception e) {
log.error("失败监听者模式 处理失败 ", e);
throw e;
} finally {
RetrySiteSnapshot.setStatus(RetrySiteSnapshot.EnumStatus.COMPLETE.getStatus());
}
doGetRetryErrorConsumer(retryerInfo, params).accept(throwable);

View File

@ -162,10 +162,10 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
switch (retryType) {
case ONLY_LOCAL:
case LOCAL_REMOTE:
LogUtils.error(log,"[{}] 执行本地重试失败,第[{}]次重试", retryerInfo.getScene(), attempt.getAttemptNumber());
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());
@ -176,10 +176,10 @@ public class LocalRetryStrategies extends AbstractRetryStrategies {
switch (retryType) {
case ONLY_LOCAL:
case LOCAL_REMOTE:
LogUtils.info(log,"[{}] 执行本地重试成功.", retryerInfo.getScene());
LogUtils.info(log,"[{}] 本地重试执行成功.", retryerInfo.getScene());
break;
case ONLY_REMOTE:
LogUtils.info(log,"[{}] 执行上报服务端成功.", retryerInfo.getScene());
LogUtils.info(log,"[{}] 上报服务端执行成功.", retryerInfo.getScene());
break;
default:
throw new EasyRetryClientException("异常重试模式 [{}]", retryType.name());

View File

@ -8,10 +8,12 @@ import com.aizuda.easy.retry.template.datasource.access.task.RetryTaskAccess;
import com.aizuda.easy.retry.template.datasource.enums.OperationTypeEnum;
import com.aizuda.easy.retry.template.datasource.exception.EasyRetryDatasourceException;
import com.aizuda.easy.retry.template.datasource.persistence.po.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* 数据处理模板类
@ -22,9 +24,18 @@ import java.util.List;
*/
@Component
public class AccessTemplate {
protected Map<String, Access> REGISTER_ACCESS = new HashMap<>();
public AccessTemplate(List<Access> accesses) {
@Autowired
private List<Access> accesses;
for (Access access : accesses) {
for (final OperationTypeEnum typeEnum : OperationTypeEnum.values()) {
if (access.supports(typeEnum.name())) {
REGISTER_ACCESS.put(typeEnum.name(), access);
break;
}
}
}
}
/**
* 获取重试任务操作类
@ -32,14 +43,8 @@ public class AccessTemplate {
* @return {@link RetryTaskAccess} 重试任务操作类
*/
public TaskAccess<RetryTask> getRetryTaskAccess() {
for (Access access : accesses) {
if (access.supports(OperationTypeEnum.RETRY_TASK.name())) {
return (TaskAccess<RetryTask>) access;
}
}
throw new EasyRetryDatasourceException("not supports operation type");
return (TaskAccess<RetryTask>) Optional.ofNullable(REGISTER_ACCESS.get(OperationTypeEnum.RETRY_TASK.name()))
.orElseThrow(() -> new EasyRetryDatasourceException("not supports operation type"));
}
/**
@ -48,14 +53,10 @@ public class AccessTemplate {
* @return {@link RetryDeadLetterTaskAccess} 获取死信任务操作类
*/
public TaskAccess<RetryDeadLetter> getRetryDeadLetterAccess() {
return (TaskAccess<RetryDeadLetter>) Optional.ofNullable(
REGISTER_ACCESS.get(OperationTypeEnum.RETRY_DEAD_LETTER.name()))
.orElseThrow(() -> new EasyRetryDatasourceException("not supports operation type"));
for (Access access : accesses) {
if (access.supports(OperationTypeEnum.RETRY_DEAD_LETTER.name())) {
return (TaskAccess<RetryDeadLetter>) access;
}
}
throw new EasyRetryDatasourceException("not supports operation type");
}
/**
@ -64,14 +65,9 @@ public class AccessTemplate {
* @return {@link SceneConfigAccess} 获取场景配置操作类
*/
public ConfigAccess<SceneConfig> getSceneConfigAccess() {
return (ConfigAccess<SceneConfig>) Optional.ofNullable(REGISTER_ACCESS.get(OperationTypeEnum.SCENE.name()))
.orElseThrow(() -> new EasyRetryDatasourceException("not supports operation type"));
for (Access access : accesses) {
if (access.supports(OperationTypeEnum.SCENE.name())) {
return (ConfigAccess<SceneConfig>) access;
}
}
throw new EasyRetryDatasourceException("not supports operation type");
}
/**
@ -80,14 +76,9 @@ public class AccessTemplate {
* @return {@link GroupConfigAccess} 获取组配置操作类
*/
public ConfigAccess<GroupConfig> getGroupConfigAccess() {
return (ConfigAccess<GroupConfig>) Optional.ofNullable(REGISTER_ACCESS.get(OperationTypeEnum.GROUP.name()))
.orElseThrow(() -> new EasyRetryDatasourceException("not supports operation type"));
for (Access access : accesses) {
if (access.supports(OperationTypeEnum.GROUP.name())) {
return (ConfigAccess<GroupConfig>) access;
}
}
throw new EasyRetryDatasourceException("not supports operation type");
}
/**
@ -96,14 +87,9 @@ public class AccessTemplate {
* @return {@link NotifyConfigAccess} 获取通知配置操作类
*/
public ConfigAccess<NotifyConfig> getNotifyConfigAccess() {
return (ConfigAccess<NotifyConfig>) Optional.ofNullable(REGISTER_ACCESS.get(OperationTypeEnum.NOTIFY.name()))
.orElseThrow(() -> new EasyRetryDatasourceException("not supports operation type"));
for (Access access : accesses) {
if (access.supports(OperationTypeEnum.GROUP.name())) {
return (ConfigAccess<NotifyConfig>) access;
}
}
throw new EasyRetryDatasourceException("not supports operation type");
}
}

View File

@ -36,7 +36,7 @@ public abstract class AbstractConfigAccess<T> implements ConfigAccess<T> {
protected GroupConfigMapper groupConfigMapper;
@Autowired
protected Environment environment;
protected static final List<String> ALLOW_DB = Arrays.asList(DbTypeEnum.MYSQL.getDb(),
protected static final List<String> ALLOW_DB = Arrays.asList(DbTypeEnum.MYSQL.getDb(),
DbTypeEnum.MARIADB.getDb(),
DbTypeEnum.POSTGRES.getDb());