diff --git a/kenaito-config-common/src/main/java/cn/odboy/config/model/ClientProp.java b/kenaito-config-common/src/main/java/cn/odboy/config/model/ClientProp.java new file mode 100644 index 0000000..4ebc8a7 --- /dev/null +++ b/kenaito-config-common/src/main/java/cn/odboy/config/model/ClientProp.java @@ -0,0 +1,14 @@ +package cn.odboy.config.model; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class ClientProp implements Serializable { + private String server; + private Integer port; + private String env; + private String dataId; + private String cacheDir; +} diff --git a/kenaito-config-common/src/main/java/cn/odboy/config/model/Message.java b/kenaito-config-common/src/main/java/cn/odboy/config/model/Message.java index 7ca1983..d25320a 100644 --- a/kenaito-config-common/src/main/java/cn/odboy/config/model/Message.java +++ b/kenaito-config-common/src/main/java/cn/odboy/config/model/Message.java @@ -17,5 +17,5 @@ public class Message implements Serializable { * updateConfig 更新配置
*/ private String type; - + private Object data; } diff --git a/kenaito-config-core/src/main/java/cn/odboy/config/context/ClientConfigLoader.java b/kenaito-config-core/src/main/java/cn/odboy/config/context/ClientConfigLoader.java index f4f7b98..9af4480 100644 --- a/kenaito-config-core/src/main/java/cn/odboy/config/context/ClientConfigLoader.java +++ b/kenaito-config-core/src/main/java/cn/odboy/config/context/ClientConfigLoader.java @@ -1,6 +1,7 @@ package cn.odboy.config.context; import cn.hutool.core.io.FileUtil; +import cn.odboy.config.model.ClientProp; import cn.odboy.config.netty.ConfigClient; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; @@ -46,6 +47,10 @@ public class ClientConfigLoader { */ private static final String DEFAULT_PATH_SEP_WIN = "\\"; private static final String DEFAULT_PATH_SEP_MAC = "/"; + /** + * 当前客户端配置 + */ + public static ClientProp clientProp = new ClientProp(); @Bean public BeanFactoryPostProcessor configLoader(ConfigurableEnvironment environment) { @@ -53,17 +58,17 @@ public class ClientConfigLoader { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String defaultCacheDir = getDefaultCacheDir(); - ClientProp.server = environment.getProperty(DEFAULT_CONFIG_NAME_SERVER, String.class, DEFAULT_CONFIG_SERVER); - ClientProp.port = environment.getProperty(DEFAULT_CONFIG_NAME_PORT, Integer.class, DEFAULT_CONFIG_PORT); - ClientProp.env = environment.getProperty(DEFAULT_CONFIG_NAME_ENV, String.class, DEFAULT_CONFIG_ENV); - ClientProp.dataId = environment.getProperty(DEFAULT_CONFIG_NAME_DATA_ID, String.class, DEFAULT_CONFIG_DATA_ID); - ClientProp.cacheDir = environment.getProperty(DEFAULT_CONFIG_NAME_CACHE_DIR, String.class, defaultCacheDir); - log.info("客户端属性: {}", ClientProp.toPrint()); - validateCacheDirPath(defaultCacheDir, ClientProp.cacheDir); - createCacheDir(ClientProp.cacheDir); + clientProp.setServer(environment.getProperty(DEFAULT_CONFIG_NAME_SERVER, String.class, DEFAULT_CONFIG_SERVER)); + clientProp.setPort(environment.getProperty(DEFAULT_CONFIG_NAME_PORT, Integer.class, DEFAULT_CONFIG_PORT)); + clientProp.setEnv(environment.getProperty(DEFAULT_CONFIG_NAME_ENV, String.class, DEFAULT_CONFIG_ENV)); + clientProp.setDataId(environment.getProperty(DEFAULT_CONFIG_NAME_DATA_ID, String.class, DEFAULT_CONFIG_DATA_ID)); + clientProp.setCacheDir(environment.getProperty(DEFAULT_CONFIG_NAME_CACHE_DIR, String.class, defaultCacheDir)); + log.info("客户端属性: {}", clientProp.toString()); + validateCacheDirPath(defaultCacheDir, clientProp.getCacheDir()); + createCacheDir(clientProp.getCacheDir()); try { ConfigClient client = new ConfigClient(); - client.start(ClientProp.server, ClientProp.port); + client.start(clientProp.getServer(), clientProp.getPort()); } catch (InterruptedException e) { log.error("Netty Client Start Error", e); throw new RuntimeException(e); diff --git a/kenaito-config-core/src/main/java/cn/odboy/config/context/ClientProp.java b/kenaito-config-core/src/main/java/cn/odboy/config/context/ClientProp.java deleted file mode 100644 index 780a440..0000000 --- a/kenaito-config-core/src/main/java/cn/odboy/config/context/ClientProp.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.odboy.config.context; - -/** - * 客户端属性 - * - * @author odboy - * @date 2024-12-03 - */ -public class ClientProp { - public static String server; - public static Integer port; - public static String env; - public static String dataId; - public static String cacheDir; - - public static String toPrint() { - return String.format("server: %s, port: %s, env: %s, dataId: %s, cacheDir: %s", - server, - port, - env, - dataId, - cacheDir - ); - } -} diff --git a/kenaito-config-core/src/main/java/cn/odboy/config/netty/ConfigClientHandler.java b/kenaito-config-core/src/main/java/cn/odboy/config/netty/ConfigClientHandler.java index 0e43130..de9b79f 100644 --- a/kenaito-config-core/src/main/java/cn/odboy/config/netty/ConfigClientHandler.java +++ b/kenaito-config-core/src/main/java/cn/odboy/config/netty/ConfigClientHandler.java @@ -20,7 +20,7 @@ public class ConfigClientHandler extends ChannelInboundHandlerAdapter { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { System.err.println("当Channel处于活动状态(已经连接到它的远程节点)时被调用"); - System.err.println("MyClientHandler发送数据"); + System.err.println("注册客户端"); //ctx.writeAndFlush("测试String编解码"); // 测试对象编解码 //ctx.writeAndFlush(new ConfigKv("app.config", "张三"));