upd
This commit is contained in:
parent
9581a6d39c
commit
625dcc9699
|
@ -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;
|
||||
}
|
|
@ -17,5 +17,5 @@ public class Message implements Serializable {
|
|||
* updateConfig 更新配置<br/>
|
||||
*/
|
||||
private String type;
|
||||
|
||||
private Object data;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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", "张三"));
|
||||
|
|
Loading…
Reference in New Issue