Commit a8cdf74120ee7c2681217f229c714d2120cbd879

Authored by YunaiV
1 parent b3d8c503

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

Showing 23 changed files with 20 additions and 636 deletions
yudao-dependencies/pom.xml
... ... @@ -28,7 +28,6 @@
28 28 <dynamic-datasource.version>3.5.2</dynamic-datasource.version>
29 29 <redisson.version>3.17.7</redisson.version>
30 30 <!-- Config 配置中心相关 -->
31   - <apollo.version>2.0.1</apollo.version>
32 31 <!-- 服务保障相关 -->
33 32 <lock4j.version>2.2.2</lock4j.version>
34 33 <resilience4j.version>1.7.1</resilience4j.version>
... ... @@ -224,17 +223,6 @@
224 223 </dependency>
225 224  
226 225 <!-- Config 配置中心相关 -->
227   - <dependency>
228   - <groupId>cn.iocoder.boot</groupId>
229   - <artifactId>yudao-spring-boot-starter-config</artifactId>
230   - <version>${revision}</version>
231   - </dependency>
232   -
233   - <dependency>
234   - <groupId>com.ctrip.framework.apollo</groupId>
235   - <artifactId>apollo-client</artifactId> <!-- 引入 Apollo Client 库,实现内嵌的配置中心 -->
236   - <version>${apollo.version}</version>
237   - </dependency>
238 226  
239 227 <!-- Job 定时任务相关 -->
240 228 <dependency>
... ...
yudao-framework/pom.xml
... ... @@ -20,7 +20,6 @@
20 20 <module>yudao-spring-boot-starter-file</module>
21 21 <module>yudao-spring-boot-starter-monitor</module>
22 22 <module>yudao-spring-boot-starter-protection</module>
23   - <module>yudao-spring-boot-starter-config</module>
24 23 <module>yudao-spring-boot-starter-job</module>
25 24 <module>yudao-spring-boot-starter-mq</module>
26 25  
... ...
yudao-framework/yudao-spring-boot-starter-config/pom.xml deleted
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<project xmlns="http://maven.apache.org/POM/4.0.0"
3   - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4   - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5   - <parent>
6   - <groupId>cn.iocoder.boot</groupId>
7   - <artifactId>yudao-framework</artifactId>
8   - <version>${revision}</version>
9   - </parent>
10   - <modelVersion>4.0.0</modelVersion>
11   - <artifactId>yudao-spring-boot-starter-config</artifactId>
12   - <packaging>jar</packaging>
13   -
14   - <name>${project.artifactId}</name>
15   - <description>配置中心,基于 Apollo 魔改实现</description>
16   - <url>https://github.com/YunaiV/ruoyi-vue-pro</url>
17   -
18   - <dependencies>
19   - <dependency>
20   - <groupId>cn.iocoder.boot</groupId>
21   - <artifactId>yudao-common</artifactId>
22   - </dependency>
23   -
24   - <!-- Spring 核心 -->
25   - <dependency>
26   - <groupId>org.springframework.boot</groupId>
27   - <artifactId>spring-boot-starter</artifactId>
28   - </dependency>
29   -
30   - <!-- Config 配置中心相关 -->
31   - <dependency>
32   - <groupId>com.ctrip.framework.apollo</groupId>
33   - <artifactId>apollo-client</artifactId> <!-- 引入 Apollo Client 库,实现内嵌的配置中心 -->
34   - </dependency>
35   - </dependencies>
36   -
37   -</project>
yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/core/ConfigConsts.java deleted
1   -package cn.iocoder.yudao.framework.apollo.core;
2   -
3   -import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO;
4   -
5   -/**
6   - * 针对 {@link com.ctrip.framework.apollo.core.ConfigConsts} 的补充,主要增加:
7   - *
8   - * 1. apollo.jdbc.* 配置项的枚举
9   - *
10   - * @author 芋道源码
11   - */
12   -public class ConfigConsts {
13   -
14   - /**
15   - * {@link ConfigFrameworkDAO} 的实现类
16   - */
17   - public static final String APOLLO_JDBC_DAO = "apollo.jdbc.dao";
18   - public static final String APOLLO_JDBC_URL = "apollo.jdbc.url";
19   - public static final String APOLLO_JDBC_USERNAME = "apollo.jdbc.username";
20   - public static final String APOLLO_JDBC_PASSWORD = "apollo.jdbc.password";
21   -
22   -}
yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/ConfigFrameworkDAO.java deleted
1   -package cn.iocoder.yudao.framework.apollo.internals;
2   -
3   -import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO;
4   -
5   -import java.time.LocalDateTime;
6   -import java.util.List;
7   -
8   -/**
9   - * 配置 Framework DAO 接口
10   - *
11   - * 注意,实现类必须提供 (String jdbcUrl, String username, String password) 构造方法
12   - *
13   - * @author 芋道源码
14   - */
15   -public interface ConfigFrameworkDAO {
16   -
17   - /**
18   - * 查询是否存在比 maxUpdateTime 的更新记录数量
19   - *
20   - * @param maxUpdateTime 最大更新时间
21   - * @return 是否存在
22   - */
23   - int selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime);
24   -
25   - /**
26   - * 查询配置列表
27   - *
28   - * @return 配置列表
29   - */
30   - List<ConfigRespDTO> selectList();
31   -
32   -}
yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DBConfigRepository.java deleted
1   -package cn.iocoder.yudao.framework.apollo.internals;
2   -
3   -import cn.hutool.core.collection.CollUtil;
4   -import cn.hutool.core.util.ClassUtil;
5   -import cn.hutool.core.util.ReflectUtil;
6   -import cn.iocoder.yudao.framework.apollo.core.ConfigConsts;
7   -import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO;
8   -import com.ctrip.framework.apollo.Apollo;
9   -import com.ctrip.framework.apollo.build.ApolloInjector;
10   -import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
11   -import com.ctrip.framework.apollo.enums.ConfigSourceType;
12   -import com.ctrip.framework.apollo.internals.AbstractConfigRepository;
13   -import com.ctrip.framework.apollo.internals.ConfigRepository;
14   -import com.ctrip.framework.apollo.tracer.Tracer;
15   -import com.ctrip.framework.apollo.util.ConfigUtil;
16   -import com.ctrip.framework.apollo.util.factory.PropertiesFactory;
17   -import lombok.SneakyThrows;
18   -import lombok.extern.slf4j.Slf4j;
19   -
20   -import java.lang.reflect.Constructor;
21   -import java.time.LocalDateTime;
22   -import java.util.Comparator;
23   -import java.util.List;
24   -import java.util.Properties;
25   -import java.util.concurrent.Executors;
26   -import java.util.concurrent.ScheduledExecutorService;
27   -
28   -@Slf4j
29   -public class DBConfigRepository extends AbstractConfigRepository {
30   -
31   - private final static ScheduledExecutorService m_executorService;
32   -
33   - private static DBConfigRepository INSTANCE;
34   -
35   - static {
36   - m_executorService = Executors.newScheduledThreadPool(1,
37   - ApolloThreadFactory.create(DBConfigRepository.class.getSimpleName(), true));
38   - }
39   -
40   - private final ConfigUtil m_configUtil;
41   - private final PropertiesFactory propertiesFactory;
42   - private final String m_namespace;
43   -
44   - /**
45   - * 配置缓存,使用 Properties 存储
46   - */
47   - private volatile Properties m_configCache;
48   - /**
49   - * 缓存配置的最大更新时间,用于后续的增量轮询,判断是否有更新
50   - */
51   - private volatile LocalDateTime maxUpdateTime;
52   -
53   - /**
54   - * 配置读取 DAO
55   - */
56   - private final ConfigFrameworkDAO configFrameworkDAO;
57   -
58   - public DBConfigRepository(String namespace) {
59   - // 初始化变量
60   - this.m_namespace = namespace;
61   - this.propertiesFactory = ApolloInjector.getInstance(PropertiesFactory.class);
62   - this.m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
63   - // 初始化 DB
64   - this.configFrameworkDAO = createConfigFrameworkDAO();
65   -
66   - // 初始化加载
67   - this.trySync();
68   - // 初始化定时任务
69   - this.schedulePeriodicRefresh();
70   -
71   - // 设置单例
72   - INSTANCE = this;
73   - }
74   -
75   - @SneakyThrows
76   - private static ConfigFrameworkDAO createConfigFrameworkDAO() {
77   - String dao = System.getProperty(ConfigConsts.APOLLO_JDBC_DAO);
78   - String url = System.getProperty(ConfigConsts.APOLLO_JDBC_URL);
79   - String username = System.getProperty(ConfigConsts.APOLLO_JDBC_USERNAME);
80   - String password = System.getProperty(ConfigConsts.APOLLO_JDBC_PASSWORD);
81   - // 创建 DBConfigRepository 对象
82   - Class<? extends ConfigFrameworkDAO> clazz = ClassUtil.loadClass(dao);
83   - Constructor<? extends ConfigFrameworkDAO> constructor = ReflectUtil.getConstructor(clazz, String.class, String.class, String.class);
84   - return constructor.newInstance(url, username, password);
85   - }
86   -
87   - /**
88   - * 通知同步,
89   - */
90   - public static void noticeSync() {
91   - // 提交到线程池中,避免和 schedulePeriodicRefresh 并发问题
92   - m_executorService.submit(() -> {
93   - INSTANCE.trySync();
94   - });
95   - }
96   -
97   - @Override
98   - protected void sync() {
99   - // 第一步,尝试获取配置
100   - List<ConfigRespDTO> configs = this.loadConfigIfUpdate(this.maxUpdateTime);
101   - if (CollUtil.isEmpty(configs)) { // 如果没有更新,则返回
102   - return;
103   - }
104   -
105   - // 第二步,构建新的 Properties
106   - Properties newProperties = this.buildProperties(configs);
107   - this.m_configCache = newProperties;
108   - // 第三步,获取最大的配置时间
109   - assert configs.size() > 0; // 断言,避免告警
110   - this.maxUpdateTime = configs.stream().max(Comparator.comparing(ConfigRespDTO::getUpdateTime)).get().getUpdateTime();
111   - // 第四部,触发配置刷新!重要!!!!
112   - super.fireRepositoryChange(m_namespace, newProperties);
113   - log.info("[sync][缓存配置,数量为:{}]", configs.size());
114   - }
115   -
116   - @Override
117   - public Properties getConfig() {
118   - // 兜底,避免可能存在配置为 null 的情况
119   - if (m_configCache == null) {
120   - this.trySync();
121   - }
122   - // 返回配置
123   - return m_configCache;
124   - }
125   -
126   - @Override
127   - public void setUpstreamRepository(ConfigRepository upstreamConfigRepository) {
128   - // 啥事不做
129   - }
130   -
131   - @Override
132   - public ConfigSourceType getSourceType() {
133   - return ConfigSourceType.REMOTE;
134   - }
135   -
136   - private Properties buildProperties(List<ConfigRespDTO> configs) {
137   - Properties properties = propertiesFactory.getPropertiesInstance();
138   - configs.stream().filter(config -> !config.getDeleted()) // 过滤掉被删除的配置
139   - .forEach(config -> properties.put(config.getKey(), config.getValue()));
140   - return properties;
141   - }
142   -
143   - // ========== 定时器相关操作 ==========
144   -
145   - private void schedulePeriodicRefresh() {
146   - log.debug("Schedule periodic refresh with interval: {} {}",
147   - m_configUtil.getRefreshInterval(), m_configUtil.getRefreshIntervalTimeUnit());
148   - m_executorService.scheduleAtFixedRate(() -> {
149   - Tracer.logEvent("Apollo.ConfigService", String.format("periodicRefresh: %s", m_namespace));
150   - log.debug("refresh config for namespace: {}", m_namespace);
151   -
152   - // 执行同步. 内部已经 try catch 掉异常,无需在处理
153   - trySync();
154   -
155   - Tracer.logEvent("Apollo.Client.Version", Apollo.VERSION);
156   - }, m_configUtil.getRefreshInterval(), m_configUtil.getRefreshInterval(),
157   - m_configUtil.getRefreshIntervalTimeUnit());
158   - }
159   -
160   - // ========== 数据库相关操作 ==========
161   -
162   - /**
163   - * 如果配置发生变化,从数据库中获取最新的全量配置。
164   - * 如果未发生变化,则返回空
165   - *
166   - * @param maxUpdateTime 当前配置的最大更新时间
167   - * @return 配置列表
168   - */
169   - private List<ConfigRespDTO> loadConfigIfUpdate(LocalDateTime maxUpdateTime) {
170   - // 第一步,判断是否要更新。
171   - if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据
172   - log.info("[loadConfigIfUpdate][首次加载全量配置]");
173   - } else { // 判断数据库中是否有更新的配置
174   - if (configFrameworkDAO.selectCountByUpdateTimeGt(maxUpdateTime) == 0) {
175   - return null;
176   - }
177   - log.info("[loadConfigIfUpdate][增量加载全量配置]");
178   - }
179   - // 第二步,如果有更新,则从数据库加载所有配置
180   - return configFrameworkDAO.selectList();
181   - }
182   -
183   -}
yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DefaultXInjector.java deleted
1   -package cn.iocoder.yudao.framework.apollo.internals;
2   -
3   -import cn.iocoder.yudao.framework.apollo.spi.DBConfigFactory;
4   -import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
5   -import com.ctrip.framework.apollo.internals.*;
6   -import com.ctrip.framework.apollo.spi.*;
7   -import com.ctrip.framework.apollo.tracer.Tracer;
8   -import com.ctrip.framework.apollo.util.ConfigUtil;
9   -import com.ctrip.framework.apollo.util.factory.DefaultPropertiesFactory;
10   -import com.ctrip.framework.apollo.util.factory.PropertiesFactory;
11   -import com.ctrip.framework.apollo.util.http.DefaultHttpClient;
12   -import com.ctrip.framework.apollo.util.yaml.YamlParser;
13   -import com.google.inject.AbstractModule;
14   -import com.google.inject.Guice;
15   -import com.google.inject.Singleton;
16   -
17   -/**
18   - * Guice injector
19   - *
20   - * 基于 Guice 注入器实现类
21   - *
22   - * @author Jason Song(song_s@ctrip.com)
23   - */
24   -public class DefaultXInjector implements Injector {
25   -
26   - private final com.google.inject.Injector m_injector;
27   -
28   - public DefaultXInjector() {
29   - try {
30   - m_injector = Guice.createInjector(new ApolloModule());
31   - } catch (Throwable ex) {
32   - ApolloConfigException exception = new ApolloConfigException("Unable to initialize Guice Injector!", ex);
33   - Tracer.logError(exception);
34   - throw exception;
35   - }
36   - }
37   -
38   - @Override
39   - public <T> T getInstance(Class<T> clazz) {
40   - try {
41   - return m_injector.getInstance(clazz);
42   - } catch (Throwable ex) {
43   - Tracer.logError(ex);
44   - throw new ApolloConfigException(String.format("Unable to load instance for %s!", clazz.getName()), ex);
45   - }
46   - }
47   -
48   - @Override
49   - public <T> T getInstance(Class<T> clazz, String name) {
50   - // Guice does not support get instance by type and name
51   - return null;
52   - }
53   -
54   - private static class ApolloModule extends AbstractModule {
55   -
56   - @Override
57   - protected void configure() {
58   - bind(ConfigManager.class).to(DefaultConfigManager.class).in(Singleton.class);
59   - bind(ConfigFactoryManager.class).to(DefaultConfigFactoryManager.class).in(Singleton.class);
60   - bind(ConfigRegistry.class).to(DefaultConfigRegistry.class).in(Singleton.class);
61   -
62   - // 自定义 ConfigFactory 实现,使用 DB 作为数据源
63   - bind(ConfigFactory.class).to(DBConfigFactory.class).in(Singleton.class);
64   -
65   - bind(ConfigUtil.class).in(Singleton.class);
66   - bind(DefaultHttpClient.class).in(Singleton.class);
67   - bind(ConfigServiceLocator.class).in(Singleton.class);
68   - bind(RemoteConfigLongPollService.class).in(Singleton.class);
69   - bind(YamlParser.class).in(Singleton.class);
70   - bind(PropertiesFactory.class).to(DefaultPropertiesFactory.class).in(Singleton.class);
71   - }
72   -
73   - }
74   -
75   -}
yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/dto/ConfigRespDTO.java deleted
1   -package cn.iocoder.yudao.framework.apollo.internals.dto;
2   -
3   -import lombok.Data;
4   -
5   -import java.time.LocalDateTime;
6   -
7   -/**
8   - * 配置 Response DTO
9   - *
10   - * @author 芋道源码
11   - */
12   -@Data
13   -public class ConfigRespDTO {
14   -
15   - /**
16   - * 参数键名
17   - */
18   - private String key;
19   - /**
20   - * 参数键值
21   - */
22   - private String value;
23   -
24   - /**
25   - * 是否删除
26   - */
27   - private Boolean deleted;
28   - /**
29   - * 更新时间
30   - */
31   - private LocalDateTime updateTime;
32   -
33   -}
yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/package-info.java deleted
1   -/**
2   - * 配置中心客户端,基于 Apollo Client 进行简化
3   - *
4   - * 差别在于,我们使用 cn.iocoder.yudao.modules.infra.dal.dataobject.config.InfConfigDO 表作为配置源。
5   - * 当然,功能肯定也会相对少些,满足最小化诉求。
6   - *
7   - * 1. 项目初始化时,可以使用 SysConfigDO 表的配置
8   - * 2. 使用 Spring @Value 可以注入属性
9   - * 3. SysConfigDO 表的配置修改时,注入到 @Value 的属性可以刷新
10   - *
11   - * 另外,整个包结构会参考 Apollo 为主,方便维护与理解
12   - */
13   -package cn.iocoder.yudao.framework.apollo;
yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/spi/DBConfigFactory.java deleted
1   -package cn.iocoder.yudao.framework.apollo.spi;
2   -
3   -import cn.iocoder.yudao.framework.apollo.internals.DBConfigRepository;
4   -import com.ctrip.framework.apollo.Config;
5   -import com.ctrip.framework.apollo.ConfigFile;
6   -import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
7   -import com.ctrip.framework.apollo.internals.ConfigRepository;
8   -import com.ctrip.framework.apollo.internals.DefaultConfig;
9   -import com.ctrip.framework.apollo.spi.ConfigFactory;
10   -
11   -/**
12   - * 基于 DB 的 ConfigFactory 实现类
13   - *
14   - * @author 芋道源码
15   - */
16   -public class DBConfigFactory implements ConfigFactory {
17   -
18   - @Override
19   - public Config create(String namespace) {
20   - return new DefaultConfig(namespace, this.createDBConfigRepository(namespace));
21   - }
22   -
23   - @Override
24   - public ConfigFile createConfigFile(String namespace, ConfigFileFormat configFileFormat) {
25   - throw new UnsupportedOperationException("暂不支持 Apollo 配置文件");
26   - }
27   -
28   - private ConfigRepository createDBConfigRepository(String namespace) {
29   - return new DBConfigRepository(namespace);
30   - }
31   -
32   -}
yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java deleted
1   -package cn.iocoder.yudao.framework.apollo.spring.boot;
2   -
3   -import cn.iocoder.yudao.framework.apollo.core.ConfigConsts;
4   -import com.google.common.base.Strings;
5   -import org.springframework.boot.SpringApplication;
6   -import org.springframework.boot.env.EnvironmentPostProcessor;
7   -import org.springframework.core.Ordered;
8   -import org.springframework.core.env.ConfigurableEnvironment;
9   -
10   -/**
11   - * 对 {@link com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer} 的补充,目前的目的有:
12   - *
13   - * 1. 将自定义的 apollo.jdbc 设置到 System 变量中
14   - *
15   - * @author 芋道源码
16   - */
17   -public class ApolloApplicationContextInitializer implements EnvironmentPostProcessor, Ordered {
18   -
19   - /**
20   - * 优先级更高,要早于 Apollo 的 ApolloApplicationContextInitializer 的初始化
21   - */
22   - public static final int DEFAULT_ORDER = -1;
23   -
24   - private int order = DEFAULT_ORDER;
25   -
26   - private static final String[] APOLLO_SYSTEM_PROPERTIES = {ConfigConsts.APOLLO_JDBC_DAO,
27   - ConfigConsts.APOLLO_JDBC_URL, ConfigConsts.APOLLO_JDBC_USERNAME, ConfigConsts.APOLLO_JDBC_PASSWORD};
28   -
29   - @Override
30   - public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
31   - initializeSystemProperty(environment);
32   - }
33   -
34   - /**
35   - * To fill system properties from environment config
36   - */
37   - void initializeSystemProperty(ConfigurableEnvironment environment) {
38   - for (String propertyName : APOLLO_SYSTEM_PROPERTIES) {
39   - fillSystemPropertyFromEnvironment(environment, propertyName);
40   - }
41   - }
42   -
43   - private void fillSystemPropertyFromEnvironment(ConfigurableEnvironment environment, String propertyName) {
44   - if (System.getProperty(propertyName) != null) {
45   - return;
46   - }
47   - String propertyValue = environment.getProperty(propertyName);
48   - if (Strings.isNullOrEmpty(propertyValue)) {
49   - return;
50   - }
51   - System.setProperty(propertyName, propertyValue);
52   - }
53   -
54   - @Override
55   - public int getOrder() {
56   - return order;
57   - }
58   -
59   - public void setOrder(int order) {
60   - this.order = order;
61   - }
62   -
63   -}
yudao-framework/yudao-spring-boot-starter-config/src/main/resources/META-INF/services/com.ctrip.framework.apollo.internals.Injector deleted
1   -cn.iocoder.yudao.framework.apollo.internals.DefaultXInjector
yudao-framework/yudao-spring-boot-starter-config/src/main/resources/META-INF/spring.factories deleted
1   -org.springframework.boot.env.EnvironmentPostProcessor=\
2   - cn.iocoder.yudao.framework.apollo.spring.boot.ApolloApplicationContextInitializer
yudao-module-infra/yudao-module-infra-biz/pom.xml
... ... @@ -58,10 +58,6 @@
58 58 </dependency>
59 59  
60 60 <!-- Config 配置中心相关 -->
61   - <dependency>
62   - <groupId>cn.iocoder.boot</groupId>
63   - <artifactId>yudao-spring-boot-starter-config</artifactId>
64   - </dependency>
65 61  
66 62 <!-- Job 定时任务相关 -->
67 63 <dependency>
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigDAOImpl.java deleted
1   -package cn.iocoder.yudao.module.infra.dal.mysql.config;
2   -
3   -import cn.hutool.core.date.LocalDateTimeUtil;
4   -import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO;
5   -import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO;
6   -import org.springframework.jdbc.core.JdbcTemplate;
7   -import org.springframework.jdbc.datasource.DriverManagerDataSource;
8   -
9   -import javax.sql.DataSource;
10   -import java.time.LocalDateTime;
11   -import java.util.List;
12   -
13   -/**
14   - * ConfigDAOImpl 实现类
15   - *
16   - * @author 芋道源码
17   - */
18   -public class ConfigDAOImpl implements ConfigFrameworkDAO {
19   -
20   - private final JdbcTemplate jdbcTemplate;
21   -
22   - public ConfigDAOImpl(String jdbcUrl, String username, String password) {
23   - DataSource dataSource = new DriverManagerDataSource(jdbcUrl, username, password);
24   - this.jdbcTemplate = new JdbcTemplate(dataSource);
25   - }
26   -
27   - @Override
28   - public int selectCountByUpdateTimeGt(LocalDateTime maxUpdateTime) {
29   - return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM infra_config WHERE update_time > ?",
30   - Integer.class, maxUpdateTime);
31   - }
32   -
33   - @Override
34   - public List<ConfigRespDTO> selectList() {
35   - return jdbcTemplate.query("SELECT config_key, value, update_time, deleted FROM infra_config",
36   - (rs, rowNum) -> new ConfigRespDTO().setKey(rs.getString("config_key"))
37   - .setValue(rs.getString("value"))
38   - .setUpdateTime(LocalDateTimeUtil.of(rs.getDate("update_time")))
39   - .setDeleted(rs.getBoolean("deleted")));
40   - }
41   -
42   -}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/consumer/config/ConfigRefreshConsumer.java deleted
1   -package cn.iocoder.yudao.module.infra.mq.consumer.config;
2   -
3   -import cn.iocoder.yudao.framework.apollo.internals.DBConfigRepository;
4   -import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener;
5   -import cn.iocoder.yudao.module.infra.mq.message.config.ConfigRefreshMessage;
6   -import lombok.extern.slf4j.Slf4j;
7   -import org.springframework.stereotype.Component;
8   -
9   -/**
10   - * 针对 {@link ConfigRefreshMessage} 的消费者
11   - *
12   - * @author 芋道源码
13   - */
14   -@Component
15   -@Slf4j
16   -public class ConfigRefreshConsumer extends AbstractChannelMessageListener<ConfigRefreshMessage> {
17   -
18   - @Override
19   - public void onMessage(ConfigRefreshMessage message) {
20   - log.info("[onMessage][收到 Config 刷新消息]");
21   - DBConfigRepository.noticeSync();
22   - }
23   -
24   -}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/consumer/package-info.java 0 → 100644
  1 +/**
  2 + * 占位符,避免缩进
  3 + */
  4 +package cn.iocoder.yudao.module.infra.mq.consumer;
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/message/config/ConfigRefreshMessage.java deleted
1   -package cn.iocoder.yudao.module.infra.mq.message.config;
2   -
3   -import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage;
4   -import lombok.Data;
5   -
6   -/**
7   - * 配置数据刷新 Message
8   - */
9   -@Data
10   -public class ConfigRefreshMessage extends AbstractChannelMessage {
11   -
12   - @Override
13   - public String getChannel() {
14   - return "infra.config.refresh";
15   - }
16   -
17   -}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/message/package-info.java 0 → 100644
  1 +/**
  2 + * 占位符,避免缩进
  3 + */
  4 +package cn.iocoder.yudao.module.infra.mq.message;
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/producer/config/ConfigProducer.java deleted
1   -package cn.iocoder.yudao.module.infra.mq.producer.config;
2   -
3   -import cn.iocoder.yudao.module.infra.mq.message.config.ConfigRefreshMessage;
4   -import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate;
5   -import org.springframework.stereotype.Component;
6   -
7   -import javax.annotation.Resource;
8   -
9   -/**
10   - * Config 配置相关消息的 Producer
11   - */
12   -@Component
13   -public class ConfigProducer {
14   -
15   - @Resource
16   - private RedisMQTemplate redisMQTemplate;
17   -
18   - /**
19   - * 发送 {@link ConfigRefreshMessage} 消息
20   - */
21   - public void sendConfigRefreshMessage() {
22   - ConfigRefreshMessage message = new ConfigRefreshMessage();
23   - redisMQTemplate.send(message);
24   - }
25   -
26   -}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/mq/producer/package-info.java 0 → 100644
  1 +/**
  2 + * 占位符,避免缩进
  3 + */
  4 +package cn.iocoder.yudao.module.infra.mq.producer;
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java
1 1 package cn.iocoder.yudao.module.infra.service.config;
2 2  
3 3 import cn.hutool.core.util.StrUtil;
4   -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
5 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 5 import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO;
7 6 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;
12 11 import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper;
13 12 import cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants;
14 13 import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum;
15   -import cn.iocoder.yudao.module.infra.mq.producer.config.ConfigProducer;
16 14 import com.google.common.annotations.VisibleForTesting;
17 15 import lombok.extern.slf4j.Slf4j;
18 16 import org.springframework.stereotype.Service;
... ... @@ -21,6 +19,8 @@ import org.springframework.validation.annotation.Validated;
21 19 import javax.annotation.Resource;
22 20 import java.util.List;
23 21  
  22 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  23 +
24 24 /**
25 25 * 参数配置 Service 实现类
26 26 */
... ... @@ -32,9 +32,6 @@ public class ConfigServiceImpl implements ConfigService {
32 32 @Resource
33 33 private ConfigMapper configMapper;
34 34  
35   - @Resource
36   - private ConfigProducer configProducer;
37   -
38 35 @Override
39 36 public Long createConfig(ConfigCreateReqVO reqVO) {
40 37 // 校验正确性
... ... @@ -43,8 +40,6 @@ public class ConfigServiceImpl implements ConfigService {
43 40 ConfigDO config = ConfigConvert.INSTANCE.convert(reqVO);
44 41 config.setType(ConfigTypeEnum.CUSTOM.getType());
45 42 configMapper.insert(config);
46   - // 发送刷新消息
47   - configProducer.sendConfigRefreshMessage();
48 43 return config.getId();
49 44 }
50 45  
... ... @@ -54,9 +49,7 @@ public class ConfigServiceImpl implements ConfigService {
54 49 checkCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key
55 50 // 更新参数配置
56 51 ConfigDO updateObj = ConfigConvert.INSTANCE.convert(reqVO);
57   - configMapper.updateById(updateObj);
58   - // 发送刷新消息
59   - configProducer.sendConfigRefreshMessage();
  52 + configMapper.updateById(updateObj);;
60 53 }
61 54  
62 55 @Override
... ... @@ -65,12 +58,10 @@ public class ConfigServiceImpl implements ConfigService {
65 58 ConfigDO config = checkConfigExists(id);
66 59 // 内置配置,不允许删除
67 60 if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
68   - throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
  61 + throw exception(ErrorCodeConstants.CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
69 62 }
70 63 // 删除
71 64 configMapper.deleteById(id);
72   - // 发送刷新消息
73   - configProducer.sendConfigRefreshMessage();
74 65 }
75 66  
76 67 @Override
... ... @@ -109,7 +100,7 @@ public class ConfigServiceImpl implements ConfigService {
109 100 }
110 101 ConfigDO config = configMapper.selectById(id);
111 102 if (config == null) {
112   - throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_NOT_EXISTS);
  103 + throw exception(ErrorCodeConstants.CONFIG_NOT_EXISTS);
113 104 }
114 105 return config;
115 106 }
... ... @@ -122,10 +113,10 @@ public class ConfigServiceImpl implements ConfigService {
122 113 }
123 114 // 如果 id 为空,说明不用比较是否为相同 id 的参数配置
124 115 if (id == null) {
125   - throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE);
  116 + throw exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE);
126 117 }
127 118 if (!config.getId().equals(id)) {
128   - throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE);
  119 + throw exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE);
129 120 }
130 121 }
131 122  
... ...
yudao-server/src/main/resources/application.yaml
... ... @@ -96,7 +96,7 @@ yudao:
96 96 version: ${yudao.info.version}
97 97 base-package: ${yudao.info.base-package}
98 98 captcha:
99   - enable: true # 验证码的开关,默认为 true;注意,优先读取数据库 infra_config 的 yudao.captcha.enable,所以请从数据库修改,可能需要重启项目
  99 + enable: true # 验证码的开关,默认为 true
100 100 codegen:
101 101 base-package: ${yudao.info.base-package}
102 102 db-schemas: ${spring.datasource.dynamic.datasource.master.name}
... ...