【移除】Apollo 配置中心,简化学习成本

This commit is contained in:
YunaiV
2022-11-12 09:52:36 +08:00
parent b3d8c503f5
commit a8cdf74120
23 changed files with 20 additions and 636 deletions

View File

@ -58,10 +58,6 @@
</dependency>
<!-- Config 配置中心相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-config</artifactId>
</dependency>
<!-- Job 定时任务相关 -->
<dependency>

View File

@ -1,42 +0,0 @@
package cn.iocoder.yudao.module.infra.dal.mysql.config;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO;
import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
import java.time.LocalDateTime;
import java.util.List;
/**
* ConfigDAOImpl 实现类
*
* @author 芋道源码
*/
public class ConfigDAOImpl implements ConfigFrameworkDAO {
private final JdbcTemplate jdbcTemplate;
public ConfigDAOImpl(String jdbcUrl, String username, String password) {
DataSource dataSource = new DriverManagerDataSource(jdbcUrl, username, password);
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public int selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime) {
return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM infra_config WHERE update_time > ?",
Integer.class, maxUpdateTime);
}
@Override
public List<ConfigRespDTO> selectList() {
return jdbcTemplate.query("SELECT config_key, value, update_time, deleted FROM infra_config",
(rs, rowNum) -> new ConfigRespDTO().setKey(rs.getString("config_key"))
.setValue(rs.getString("value"))
.setUpdateTime(LocalDateTimeUtil.of(rs.getDate("update_time")))
.setDeleted(rs.getBoolean("deleted")));
}
}

View File

@ -1,24 +0,0 @@
package cn.iocoder.yudao.module.infra.mq.consumer.config;
import cn.iocoder.yudao.framework.apollo.internals.DBConfigRepository;
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener;
import cn.iocoder.yudao.module.infra.mq.message.config.ConfigRefreshMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 针对 {@link ConfigRefreshMessage} 的消费者
*
* @author 芋道源码
*/
@Component
@Slf4j
public class ConfigRefreshConsumer extends AbstractChannelMessageListener<ConfigRefreshMessage> {
@Override
public void onMessage(ConfigRefreshMessage message) {
log.info("[onMessage][收到 Config 刷新消息]");
DBConfigRepository.noticeSync();
}
}

View File

@ -0,0 +1,4 @@
/**
* 占位符,避免缩进
*/
package cn.iocoder.yudao.module.infra.mq.consumer;

View File

@ -1,17 +0,0 @@
package cn.iocoder.yudao.module.infra.mq.message.config;
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage;
import lombok.Data;
/**
* 配置数据刷新 Message
*/
@Data
public class ConfigRefreshMessage extends AbstractChannelMessage {
@Override
public String getChannel() {
return "infra.config.refresh";
}
}

View File

@ -0,0 +1,4 @@
/**
* 占位符,避免缩进
*/
package cn.iocoder.yudao.module.infra.mq.message;

View File

@ -1,26 +0,0 @@
package cn.iocoder.yudao.module.infra.mq.producer.config;
import cn.iocoder.yudao.module.infra.mq.message.config.ConfigRefreshMessage;
import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* Config 配置相关消息的 Producer
*/
@Component
public class ConfigProducer {
@Resource
private RedisMQTemplate redisMQTemplate;
/**
* 发送 {@link ConfigRefreshMessage} 消息
*/
public void sendConfigRefreshMessage() {
ConfigRefreshMessage message = new ConfigRefreshMessage();
redisMQTemplate.send(message);
}
}

View File

@ -0,0 +1,4 @@
/**
* 占位符,避免缩进
*/
package cn.iocoder.yudao.module.infra.mq.producer;

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.infra.service.config;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO;
@ -12,7 +11,6 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO;
import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper;
import cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum;
import cn.iocoder.yudao.module.infra.mq.producer.config.ConfigProducer;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -21,6 +19,8 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* 参数配置 Service 实现类
*/
@ -32,9 +32,6 @@ public class ConfigServiceImpl implements ConfigService {
@Resource
private ConfigMapper configMapper;
@Resource
private ConfigProducer configProducer;
@Override
public Long createConfig(ConfigCreateReqVO reqVO) {
// 校验正确性
@ -43,8 +40,6 @@ public class ConfigServiceImpl implements ConfigService {
ConfigDO config = ConfigConvert.INSTANCE.convert(reqVO);
config.setType(ConfigTypeEnum.CUSTOM.getType());
configMapper.insert(config);
// 发送刷新消息
configProducer.sendConfigRefreshMessage();
return config.getId();
}
@ -54,9 +49,7 @@ public class ConfigServiceImpl implements ConfigService {
checkCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key
// 更新参数配置
ConfigDO updateObj = ConfigConvert.INSTANCE.convert(reqVO);
configMapper.updateById(updateObj);
// 发送刷新消息
configProducer.sendConfigRefreshMessage();
configMapper.updateById(updateObj);;
}
@Override
@ -65,12 +58,10 @@ public class ConfigServiceImpl implements ConfigService {
ConfigDO config = checkConfigExists(id);
// 内置配置,不允许删除
if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
throw exception(ErrorCodeConstants.CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
}
// 删除
configMapper.deleteById(id);
// 发送刷新消息
configProducer.sendConfigRefreshMessage();
}
@Override
@ -109,7 +100,7 @@ public class ConfigServiceImpl implements ConfigService {
}
ConfigDO config = configMapper.selectById(id);
if (config == null) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_NOT_EXISTS);
throw exception(ErrorCodeConstants.CONFIG_NOT_EXISTS);
}
return config;
}
@ -122,10 +113,10 @@ public class ConfigServiceImpl implements ConfigService {
}
// 如果 id 为空,说明不用比较是否为相同 id 的参数配置
if (id == null) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE);
throw exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE);
}
if (!config.getId().equals(id)) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE);
throw exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE);
}
}