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 b4cc62c..8612eb9 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 @@ -121,7 +121,7 @@ public class ClientConfigLoader { StandardCharsets.UTF_8); } catch (Exception e) { logger.error( - "ClientConfigLoader -> 应用 {},环境 {},缓存配置文件 {} 失败", + "应用 {},环境 {},缓存配置文件 {} 失败", clientInfo.getDataId(), clientInfo.getEnv(), kve.getKey(), @@ -141,7 +141,7 @@ public class ClientConfigLoader { throws BeansException { String defaultCacheDir = getDefaultCacheDir(); initClientInfo(defaultCacheDir, environment); - logger.info("ClientConfigLoader -> 客户端属性: {}", clientInfo); + logger.info("客户端属性: {}", clientInfo); validateCacheDirPath(defaultCacheDir, clientInfo.getCacheDir()); createCacheDir(clientInfo.getCacheDir()); fixedTimeFlushConfigFileThread.start(); @@ -150,7 +150,7 @@ public class ClientConfigLoader { try { ConfigClient.getInstance().start(clientInfo.getServer(), clientInfo.getPort()); } catch (InterruptedException e) { - logger.error("ClientConfigLoader -> Netty客户端启动失败", e); + logger.error("Netty客户端启动失败", e); throw new RuntimeException(e); } }); @@ -164,12 +164,12 @@ public class ClientConfigLoader { Thread currentThread = Thread.currentThread(); String currentThreadName = currentThread.getName(); currentThread.interrupt(); - logger.error("ClientConfigLoader -> 中断线程: {}", currentThreadName, e); + logger.error("中断线程: {}", currentThreadName, e); } } // 判断配置中心服务是否处于离线状态 if (isServerOffline) { - logger.info("ClientConfigLoader -> 配置中心离线,尝试从本地缓存加载配置文件"); + logger.info("配置中心离线,尝试从本地缓存加载配置文件"); String cacheDir = clientInfo.getCacheDir(); FileUtil.walkFiles( FileUtil.file(cacheDir), @@ -197,7 +197,7 @@ public class ClientConfigLoader { lastConfigs.put(fileName, tempMap); } } catch (Exception e) { - logger.info("ClientConfigLoader -> 配置文件转map失败", e); + logger.info("配置文件转map失败", e); } })); } diff --git a/kenaito-config-core/src/main/java/cn/odboy/config/netty/ConfigClient.java b/kenaito-config-core/src/main/java/cn/odboy/config/netty/ConfigClient.java index 7787f1c..79d8ac2 100644 --- a/kenaito-config-core/src/main/java/cn/odboy/config/netty/ConfigClient.java +++ b/kenaito-config-core/src/main/java/cn/odboy/config/netty/ConfigClient.java @@ -43,7 +43,7 @@ public class ConfigClient { private static volatile ConfigClient instance; /** 最大重试次数 */ - private static final int MAX_RETRY_COUNT = 2; + private static final int MAX_RETRY_COUNT = 5; /** 当前重试次数 */ private static int retryCount = 0; @@ -90,7 +90,7 @@ public class ConfigClient { } private void doConnect(String server, Integer port) throws InterruptedException { - logger.info("ConfigClient -> Start"); + logger.info("开始连接配置中心服务..."); if (channel != null && channel.isActive()) { return; } @@ -107,11 +107,11 @@ public class ConfigClient { channel = channelFuture.channel(); // 重置重试次数 retryCount = 0; - logger.info("ConfigClient -> Connect success {}:{}", serverIp, serverPort); + logger.info("连接成功 {}:{}", serverIp, serverPort); } else { // 失败后delaySecond秒(默认是5秒)重连,周期性delaySecond秒的重连 retryCount++; - logger.info("ConfigClient -> 当前重试次数: {}", retryCount); + logger.info("当前重试次数: {}", retryCount); if (retryCount >= MAX_RETRY_COUNT) { ClientConfigLoader.isConfigLoaded = true; ClientConfigLoader.isServerOffline = true; @@ -133,13 +133,11 @@ public class ConfigClient { /** 重新连接 */ protected void reConnect() { try { - logger.info( - "ConfigClient -> Start reconnect to server.{}:{}", this.serverIp, this.serverPort); + logger.info("重连配置中心服务 {}:{}", this.serverIp, this.serverPort); ClientConfigLoader.isConfigLoaded = false; ClientConfigLoader.isServerOffline = false; if (channel != null && channel.isOpen()) { - logger.info( - "ConfigClient -> Server [{}] channel is active, close it and reconnect", this.serverIp); + logger.info("Channel已激活, 关闭且重启中..."); channel.close(); } bootstrap @@ -148,11 +146,7 @@ public class ConfigClient { .sync() .channel(); } catch (Exception e) { - logger.error( - "ConfigClient -> ReConnect to server failure. server={}:{}:{}", - this.serverIp, - this.serverPort, - e.getMessage()); + logger.error("重连配置中心服务失败 {}:{}", this.serverIp, this.serverPort, e); } } } 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 39fdaa1..2a1e30e 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 @@ -29,17 +29,17 @@ public class ConfigClientHandler extends ChannelInboundHandlerAdapter { @Override public void channelRegistered(ChannelHandlerContext ctx) throws Exception { - logger.info("ConfigClientHandler -> 当Channel已经注册到它的EventLoop并且能够处理I/O时被调用"); + logger.info("当Channel已经注册到它的EventLoop并且能够处理I/O时被调用"); } @Override public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { - logger.info("ConfigClientHandler -> 当Channel从它的EventLoop注销并且无法处理任何I/O时被调用"); + logger.info("当Channel从它的EventLoop注销并且无法处理任何I/O时被调用"); } @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { - logger.info("ConfigClientHandler -> 当Channel处于活动状态(已经连接到它的远程节点)时被调用, 注册客户端"); + logger.info("当Channel处于活动状态(已经连接到它的远程节点)时被调用, 注册客户端"); SmallMessage smallMessage = new SmallMessage(); smallMessage.setType(TransferMessageType.REGISTER); smallMessage.setResp(SmallMessage.Response.ok(ClientConfigLoader.clientInfo)); @@ -48,22 +48,22 @@ public class ConfigClientHandler extends ChannelInboundHandlerAdapter { @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { - logger.info("ConfigClientHandler -> 当Channel离开活动状态并且不再连接到它的远程节点时被调用"); + logger.info("当Channel离开活动状态并且不再连接到它的远程节点时被调用"); /// this.configClient.reConnect(); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - /// logger.info("ConfigClientHandler -> 当从Channel读取数据时被调用, 收到服务器消息"); - logger.info("ConfigClientHandler -> 从服务端读取到Object"); + /// logger.info("当从Channel读取数据时被调用, 收到服务器消息"); + logger.info("从服务端读取到Object"); SmallMessage smallMessage = MessageUtil.getMessage(msg); SmallMessage.Response resp = smallMessage.getResp(); switch (smallMessage.getType()) { case REGISTER: if (!resp.getSuccess()) { - logger.info("ConfigClientHandler -> 注册失败, {}", resp.getErrorMessage()); + logger.info("注册失败, {}", resp.getErrorMessage()); } else { - logger.info("ConfigClientHandler -> 注册成功, 给服务端发信号, 表明准备好可以拉取配置了"); + logger.info("注册成功, 给服务端发信号, 表明准备好可以拉取配置了"); // 准备拉取配置,给服务端发信号 SmallMessage pullConfigMessage = new SmallMessage(); pullConfigMessage.setType(TransferMessageType.PULL_CONFIG); @@ -76,7 +76,7 @@ public class ConfigClientHandler extends ChannelInboundHandlerAdapter { throw new RuntimeException(resp.getErrorMessage()); } List configFileInfos = MessageUtil.toConfigFileInfoList(resp.getData()); - logger.info("ConfigClientHandler -> 收到来自服务端推送的配置信息"); + logger.info("收到来自服务端推送的配置信息"); Map originConfigs = new HashMap<>(1); Map> lastConfigs = new HashMap<>(1); try { @@ -101,7 +101,7 @@ public class ConfigClientHandler extends ChannelInboundHandlerAdapter { lastConfigs.put(fileName, tempMap); } } - logger.info("ConfigClientHandler -> 配置文件转map成功"); + logger.info("配置文件转map成功"); ClientConfigLoader.originConfigs = originConfigs; ClientConfigLoader.lastConfigs = lastConfigs; ClientConfigLoader.isConfigLoaded = true; @@ -110,7 +110,7 @@ public class ConfigClientHandler extends ChannelInboundHandlerAdapter { ClientConfigLoader.clientInfo.notifyAll(); } } catch (IOException e) { - logger.info("ConfigClientHandler -> 配置文件转map失败", e); + logger.info("配置文件转map失败", e); } break; default: diff --git a/kenaito-config-service/src/main/java/cn/odboy/infra/netty/ConfigClientManage.java b/kenaito-config-service/src/main/java/cn/odboy/infra/netty/ConfigClientManage.java index ae075bf..c3e6b96 100644 --- a/kenaito-config-service/src/main/java/cn/odboy/infra/netty/ConfigClientManage.java +++ b/kenaito-config-service/src/main/java/cn/odboy/infra/netty/ConfigClientManage.java @@ -56,7 +56,7 @@ public class ConfigClientManage { public static void register(String env, String dataId, ChannelHandlerContext ctx) { String envClientKey = String.format("%s_%s_%s", env, dataId, ChannelUtil.getId(ctx)); CLIENT.put(envClientKey, ctx.channel()); - log.info("ConfigClientManage -> 客户端 {} 注册成功", envClientKey); + log.info("客户端 {} 注册成功", envClientKey); } /** @@ -76,7 +76,7 @@ public class ConfigClientManage { channel.closeFuture(); } CLIENT.remove(envClientKey); - log.info("ConfigClientManage -> 客户端 {} 注销成功", envClientKey); + log.info("客户端 {} 注销成功", envClientKey); } } } diff --git a/kenaito-config-service/src/main/java/cn/odboy/infra/netty/ConfigServerHandler.java b/kenaito-config-service/src/main/java/cn/odboy/infra/netty/ConfigServerHandler.java index 8135e4c..404ea3e 100644 --- a/kenaito-config-service/src/main/java/cn/odboy/infra/netty/ConfigServerHandler.java +++ b/kenaito-config-service/src/main/java/cn/odboy/infra/netty/ConfigServerHandler.java @@ -29,9 +29,9 @@ public class ConfigServerHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - /// log.info("ServerHandler -> 当从Channel读取数据时被调用"); + /// log.info("当从Channel读取数据时被调用"); SmallMessage smallMessage = MessageUtil.getMessage(msg); - log.info("ServerHandler -> 从客户端读取到Object:{}", smallMessage); + log.info("从客户端读取到Object:{}", smallMessage); SmallMessage.Response resp = smallMessage.getResp(); switch (smallMessage.getType()) { case REGISTER: @@ -53,16 +53,16 @@ public class ConfigServerHandler extends ChannelInboundHandlerAdapter { break; case PULL_CONFIG: if (!resp.getSuccess()) { - log.info("ServerHandler -> 客户端说它没有准备好拉取配置"); + log.info("客户端说它没有准备好拉取配置"); break; } - log.info("ServerHandler -> 客户端说它准备好拉取配置了"); + log.info("客户端说它准备好拉取配置了"); String[] envDataId = ConfigClientManage.getEnvDataId(ctx.channel().id()); String env = envDataId[0]; String dataId = envDataId[1]; List channels = ConfigClientManage.queryChannels(env, dataId); if (channels.isEmpty()) { - log.info("ServerHandler -> 没有在线的客户端"); + log.info("没有在线的客户端"); break; } List fileList = configFileService.getFileList(env, dataId); @@ -74,7 +74,7 @@ public class ConfigServerHandler extends ChannelInboundHandlerAdapter { MessageUtil.toPushConfigBad(String.format("应用 %s 没有环境编码为 %s 的配置", dataId, env))); } catch (Exception e) { log.error( - "ServerHandler -> 推送无法获取配置的消息到客户端失败, env: {}, dataId={}, channelId={}", + "推送无法获取配置的消息到客户端失败, env: {}, dataId={}, channelId={}", env, dataId, ChannelUtil.getId(channel.id()), @@ -87,13 +87,13 @@ public class ConfigServerHandler extends ChannelInboundHandlerAdapter { try { ctx.writeAndFlush(MessageUtil.toPushConfigOk(fileList)); log.info( - "ServerHandler -> 推送配置到客户端成功, env: {}, dataId={}, channelId={}", + "推送配置到客户端成功, env: {}, dataId={}, channelId={}", env, dataId, ChannelUtil.getId(channel.id())); } catch (Exception e) { log.error( - "ServerHandler -> 推送配置到客户端失败, env: {}, dataId={}, channelId={}", + "推送配置到客户端失败, env: {}, dataId={}, channelId={}", env, dataId, ChannelUtil.getId(channel.id()), @@ -109,7 +109,7 @@ public class ConfigServerHandler extends ChannelInboundHandlerAdapter { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - log.error("ServerHandler -> 当Channel发生异常被调用", cause); + log.error("当Channel发生异常被调用", cause); /// cause.printStackTrace(); ConfigClientManage.unregister(ctx.channel().id()); ctx.close(); @@ -117,13 +117,13 @@ public class ConfigServerHandler extends ChannelInboundHandlerAdapter { @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { - log.info("ServerHandler -> 当Channel处于非活动状态(已经连接到它的远程节点)时被调用"); + log.info("当Channel处于非活动状态(已经连接到它的远程节点)时被调用"); ConfigClientManage.unregister(ctx.channel().id()); } @Override public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { - log.info("ServerHandler -> 当Channel从它的EventLoop注销并且不能够处理I/O时被调用"); + log.info("当Channel从它的EventLoop注销并且不能够处理I/O时被调用"); ConfigClientManage.unregister(ctx.channel().id()); } }