소스 검색

升级netty服务

lgy 3 년 전
부모
커밋
0666d3d271
3개의 변경된 파일3개의 추가작업 그리고 17개의 파일을 삭제
  1. 1 1
      pom.xml
  2. 1 1
      src/main/java/com/persagy/client/GroupNettyClient.java
  3. 1 15
      src/main/java/com/persagy/client/GroupNettyClientHandler.java

+ 1 - 1
pom.xml

@@ -58,7 +58,7 @@
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-all</artifactId>
-            <version>4.1.42.Final</version>
+            <version>4.1.62.Final</version>
         </dependency>
         <!--测试工具-->
         <dependency>

+ 1 - 1
src/main/java/com/persagy/client/GroupNettyClient.java

@@ -80,9 +80,9 @@ public class GroupNettyClient {
                         @Override
                         protected void initChannel(SocketChannel ch) throws Exception {
                             ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
+                            ch.pipeline().addLast(new LengthFieldPrepender(4));
                             // 将分隔之后的字节数据转换为字符串
                             ch.pipeline().addLast(new StringDecoder());
-                            ch.pipeline().addLast(new LengthFieldPrepender(4));
                             ch.pipeline().addLast(new StringEncoder());
                             // pipeline可以理解为所有handler的初始化容器
                             ch.pipeline().addLast(new GroupNettyClientHandler(groupNettyClient, alarmDefineService, alarmRecordRepository));// 添加自定义handler

+ 1 - 15
src/main/java/com/persagy/client/GroupNettyClientHandler.java

@@ -50,20 +50,6 @@ public class GroupNettyClientHandler extends ChannelInboundHandlerAdapter {
         this.alarmRecordRepository = alarmRecordRepository;
     }
 
-    @Override
-    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
-
-        if (!(evt instanceof IdleStateEvent)) {
-            return;
-        }
-        IdleStateEvent e = (IdleStateEvent) evt;
-        if (e.state() == IdleState.READER_IDLE) {
-            log.info("no inbound traffic");
-            // The connection was OK but there was no traffic for last period.
-            // 长时间不操作的时候自动关闭连接; ctx.close();
-        }
-    }
-
     /**
      * 在到服务器的连接已经建立之后将被调用
      *
@@ -206,7 +192,7 @@ public class GroupNettyClientHandler extends ChannelInboundHandlerAdapter {
      */
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
-        cause.printStackTrace();
+        log.info("exceptionCaught",cause);
         ctx.close();
     }