feat: 2.0.0
1. 优化请求客户端的日志信息 2. 组配置校验分区时,验证对应的表是否存在
This commit is contained in:
parent
6a532ce528
commit
7c5c40f88b
@ -6,6 +6,7 @@ import cn.hutool.core.util.URLUtil;
|
|||||||
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
||||||
import com.aizuda.easy.retry.common.core.context.SpringContext;
|
import com.aizuda.easy.retry.common.core.context.SpringContext;
|
||||||
import com.aizuda.easy.retry.common.core.model.Result;
|
import com.aizuda.easy.retry.common.core.model.Result;
|
||||||
|
import com.aizuda.easy.retry.common.core.util.HostUtils;
|
||||||
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||||
import com.aizuda.easy.retry.server.client.annotation.Body;
|
import com.aizuda.easy.retry.server.client.annotation.Body;
|
||||||
import com.aizuda.easy.retry.server.client.annotation.Header;
|
import com.aizuda.easy.retry.server.client.annotation.Header;
|
||||||
@ -76,7 +77,7 @@ public class RpcClientInvokeHandler implements InvocationHandler {
|
|||||||
// 最多调用size次
|
// 最多调用size次
|
||||||
int size = serverNodeSet.size();
|
int size = serverNodeSet.size();
|
||||||
for (int count = 1; count <= size; count++) {
|
for (int count = 1; count <= size; count++) {
|
||||||
log.info("Start request client. count:[{}] hostId:[{}] addr:[{}:{}]", count, hostId, hostIp, hostPort);
|
log.info("Start request client. count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count, hostId, hostIp, hostPort, HostUtils.getIp());
|
||||||
Result result = requestRemote(method, args, annotation, count);
|
Result result = requestRemote(method, args, annotation, count);
|
||||||
if (Objects.nonNull(result)) {
|
if (Objects.nonNull(result)) {
|
||||||
return result;
|
return result;
|
||||||
@ -110,13 +111,13 @@ public class RpcClientInvokeHandler implements InvocationHandler {
|
|||||||
// 返回值类型
|
// 返回值类型
|
||||||
Result.class);
|
Result.class);
|
||||||
|
|
||||||
log.info("Request client success. count:[{}] hostId:[{}] addr:[{}:{}]", count, hostId, hostIp, hostPort);
|
log.info("Request client success. count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count, hostId, hostIp, hostPort, HostUtils.getIp());
|
||||||
|
|
||||||
return Objects.requireNonNull(response.getBody());
|
return Objects.requireNonNull(response.getBody());
|
||||||
} catch (RestClientException ex) {
|
} catch (RestClientException ex) {
|
||||||
// 网络异常
|
// 网络异常
|
||||||
if (ex instanceof ResourceAccessException) {
|
if (ex instanceof ResourceAccessException) {
|
||||||
log.error("request client I/O error, count:[{}] hostId:[{}] addr:[{}:{}]", count, hostId, hostIp, hostPort, ex);
|
log.error("request client I/O error, count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count, hostId, hostIp, hostPort, HostUtils.getIp(), ex);
|
||||||
|
|
||||||
// 进行路由剔除处理
|
// 进行路由剔除处理
|
||||||
CacheRegisterTable.remove(groupName, hostId);
|
CacheRegisterTable.remove(groupName, hostId);
|
||||||
@ -136,11 +137,11 @@ public class RpcClientInvokeHandler implements InvocationHandler {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 其他异常继续抛出
|
// 其他异常继续抛出
|
||||||
log.error("request client error.count:[{}] hostId:[{}] addr:[{}:{}]", count, hostId, hostIp, hostPort, ex);
|
log.error("request client error.count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count, hostId, hostIp, hostPort, HostUtils.getIp(), ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("request client unknown exception. count:[{}] hostId:[{}] addr:[{}:{}]", count, hostId, hostIp, hostPort, ex);
|
log.error("request client unknown exception. count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count, hostId, hostIp, hostPort, HostUtils.getIp(), ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,8 +191,8 @@ public class RpcClientInvokeHandler implements InvocationHandler {
|
|||||||
@Data
|
@Data
|
||||||
private static class ParseParasResult {
|
private static class ParseParasResult {
|
||||||
|
|
||||||
Object body = null;
|
private Object body = null;
|
||||||
HttpHeaders requestHeaders;
|
private HttpHeaders requestHeaders;
|
||||||
Map<String, Object> paramMap;
|
private Map<String, Object> paramMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,23 @@ package com.aizuda.easy.retry.server.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.HashUtil;
|
import cn.hutool.core.util.HashUtil;
|
||||||
|
import com.aizuda.easy.retry.server.config.RequestDataHelper;
|
||||||
import com.aizuda.easy.retry.server.enums.IdGeneratorMode;
|
import com.aizuda.easy.retry.server.enums.IdGeneratorMode;
|
||||||
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
|
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
|
||||||
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.GroupConfigMapper;
|
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.GroupConfigMapper;
|
||||||
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.NotifyConfigMapper;
|
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.NotifyConfigMapper;
|
||||||
|
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.RetryDeadLetterMapper;
|
||||||
|
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.RetryTaskMapper;
|
||||||
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.SceneConfigMapper;
|
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.SceneConfigMapper;
|
||||||
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.SequenceAllocMapper;
|
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.SequenceAllocMapper;
|
||||||
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.ServerNodeMapper;
|
import com.aizuda.easy.retry.server.persistence.mybatis.mapper.ServerNodeMapper;
|
||||||
import com.aizuda.easy.retry.server.persistence.mybatis.po.GroupConfig;
|
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.NotifyConfig;
|
||||||
|
import com.aizuda.easy.retry.server.persistence.mybatis.po.RetryTask;
|
||||||
import com.aizuda.easy.retry.server.persistence.mybatis.po.SceneConfig;
|
import com.aizuda.easy.retry.server.persistence.mybatis.po.SceneConfig;
|
||||||
import com.aizuda.easy.retry.server.persistence.mybatis.po.SequenceAlloc;
|
import com.aizuda.easy.retry.server.persistence.mybatis.po.SequenceAlloc;
|
||||||
import com.aizuda.easy.retry.server.persistence.mybatis.po.ServerNode;
|
import com.aizuda.easy.retry.server.persistence.mybatis.po.ServerNode;
|
||||||
|
import com.aizuda.easy.retry.server.persistence.support.RetryTaskAccess;
|
||||||
import com.aizuda.easy.retry.server.support.handler.ConfigVersionSyncHandler;
|
import com.aizuda.easy.retry.server.support.handler.ConfigVersionSyncHandler;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
@ -31,11 +36,14 @@ import com.aizuda.easy.retry.server.web.model.response.GroupConfigResponseVO;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.jdbc.BadSqlGrammarException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.sql.SQLSyntaxErrorException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -59,6 +67,10 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ServerNodeMapper serverNodeMapper;
|
private ServerNodeMapper serverNodeMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
protected RetryTaskMapper retryTaskMapper;
|
||||||
|
@Autowired
|
||||||
|
protected RetryDeadLetterMapper retryDeadLetterMapper;
|
||||||
|
@Autowired
|
||||||
private SequenceAllocMapper sequenceAllocMapper;
|
private SequenceAllocMapper sequenceAllocMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConfigVersionSyncHandler configVersionSyncHandler;
|
private ConfigVersionSyncHandler configVersionSyncHandler;
|
||||||
@ -116,6 +128,12 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
groupConfig.setVersion(groupConfig.getVersion() + 1);
|
groupConfig.setVersion(groupConfig.getVersion() + 1);
|
||||||
BeanUtils.copyProperties(groupConfigRequestVO, groupConfig);
|
BeanUtils.copyProperties(groupConfigRequestVO, groupConfig);
|
||||||
|
|
||||||
|
Assert.isTrue(totalPartition > groupConfigRequestVO.getGroupPartition(), () -> new EasyRetryServerException("分区超过最大分区. [{}]", totalPartition-1));
|
||||||
|
Assert.isTrue(groupConfigRequestVO.getGroupPartition() >= 0, () -> new EasyRetryServerException("分区不能是负数."));
|
||||||
|
|
||||||
|
// 校验retry_task_x和retry_dead_letter_x是否存在
|
||||||
|
checkGroupPartition(groupConfig);
|
||||||
|
|
||||||
Assert.isTrue(1 == groupConfigMapper.update(groupConfig,
|
Assert.isTrue(1 == groupConfigMapper.update(groupConfig,
|
||||||
new LambdaUpdateWrapper<GroupConfig>().eq(GroupConfig::getGroupName, groupConfigRequestVO.getGroupName())),
|
new LambdaUpdateWrapper<GroupConfig>().eq(GroupConfig::getGroupName, groupConfigRequestVO.getGroupName())),
|
||||||
() -> new EasyRetryServerException("exception occurred while adding group. groupConfigVO[{}]", groupConfigRequestVO));
|
() -> new EasyRetryServerException("exception occurred while adding group. groupConfigVO[{}]", groupConfigRequestVO));
|
||||||
@ -178,6 +196,37 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Assert.isTrue(1 == groupConfigMapper.insert(groupConfig), () -> new EasyRetryServerException("新增组异常异常 groupConfigVO[{}]", groupConfigRequestVO));
|
Assert.isTrue(1 == groupConfigMapper.insert(groupConfig), () -> new EasyRetryServerException("新增组异常异常 groupConfigVO[{}]", groupConfigRequestVO));
|
||||||
|
|
||||||
|
// 校验retry_task_x和retry_dead_letter_x是否存在
|
||||||
|
checkGroupPartition(groupConfig);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验retry_task_x和retry_dead_letter_x是否存在
|
||||||
|
*/
|
||||||
|
private void checkGroupPartition(GroupConfig groupConfig) {
|
||||||
|
try {
|
||||||
|
RequestDataHelper.setPartition(groupConfig.getGroupName());
|
||||||
|
retryTaskMapper.selectById(1);
|
||||||
|
} catch (BadSqlGrammarException e) {
|
||||||
|
Optional.ofNullable(e.getMessage()).ifPresent(s -> {
|
||||||
|
if (s.contains("retry_task_" + groupConfig.getGroupPartition()) && s.contains("doesn't exist")) {
|
||||||
|
throw new EasyRetryServerException("分区:[{}] '未配置表retry_task_{}', 请联系管理员进行配置", groupConfig.getGroupPartition(), groupConfig.getGroupPartition());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
RequestDataHelper.setPartition(groupConfig.getGroupName());
|
||||||
|
retryDeadLetterMapper.selectById(1);
|
||||||
|
} catch (BadSqlGrammarException e) {
|
||||||
|
Optional.ofNullable(e.getMessage()).ifPresent(s -> {
|
||||||
|
if (s.contains("retry_dead_letter_" + groupConfig.getGroupPartition()) && s.contains("doesn't exist")) {
|
||||||
|
throw new EasyRetryServerException("分区:[{}] '未配置表retry_dead_letter_{}', 请联系管理员进行配置", groupConfig.getGroupPartition(), groupConfig.getGroupPartition());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user