Skip to content

Commit e422f01

Browse files
committed
netty 机制
1 parent e51589f commit e422f01

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

tx-client/src/main/java/com/codingapi/tx/netty/service/impl/NettyServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.netty.channel.socket.SocketChannel;
1414
import io.netty.channel.socket.nio.NioSocketChannel;
1515
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
16+
import io.netty.handler.codec.LengthFieldPrepender;
1617
import io.netty.handler.timeout.IdleStateHandler;
1718
import org.slf4j.Logger;
1819
import org.slf4j.LoggerFactory;
@@ -75,7 +76,9 @@ public void initChannel(SocketChannel ch) throws Exception {
7576

7677
ch.pipeline().addLast("timeout", new IdleStateHandler(heart, heart, heart, TimeUnit.SECONDS));
7778

78-
ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 1, 1, 0, 0));
79+
ch.pipeline().addLast(new LengthFieldPrepender(4, false));
80+
ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
81+
7982

8083
ch.pipeline().addLast(transactionHandler);
8184
}

tx-manager/src/main/java/com/codingapi/tm/netty/service/impl/NettyServerServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.netty.channel.socket.SocketChannel;
1414
import io.netty.channel.socket.nio.NioServerSocketChannel;
1515
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
16+
import io.netty.handler.codec.LengthFieldPrepender;
1617
import io.netty.handler.logging.LogLevel;
1718
import io.netty.handler.logging.LoggingHandler;
1819
import io.netty.handler.timeout.IdleStateHandler;
@@ -63,7 +64,8 @@ public void start() {
6364
public void initChannel(SocketChannel ch) throws Exception {
6465
ch.pipeline().addLast("timeout", new IdleStateHandler(heartTime, heartTime, heartTime, TimeUnit.SECONDS));
6566

66-
ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 1, 1, 0, 0));
67+
ch.pipeline().addLast(new LengthFieldPrepender(4, false));
68+
ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
6769

6870
ch.pipeline().addLast(txCoreServerHandler);
6971
}

0 commit comments

Comments
 (0)