seata協議解析

代碼入口

io.seata.core.rpc.netty.NettyClientBootstrap#start

bootstrap.handler(
            new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) {
                    ChannelPipeline pipeline = ch.pipeline();
                    pipeline.addLast(
                        new IdleStateHandler(nettyClientConfig.getChannelMaxReadIdleSeconds(),
                            nettyClientConfig.getChannelMaxWriteIdleSeconds(),
                            nettyClientConfig.getChannelMaxAllIdleSeconds()))
                        .addLast(new ProtocolV1Decoder())
                        .addLast(new ProtocolV1Encoder());
                    if (channelHandlers != null) {
                        addChannelPipelineLast(ch, channelHandlers);
                    }
                }
            });

io.seata.core.rpc.netty.v1.ProtocolV1Encoder#encode

io.seata.core.protocol.RpcMessage

協議規則

2個字節的模數([-38,-38])| 1個字節的版本號 | 6個字節的長度 | 1個字節的messageType | 一個字節的codec值| 一個字節的compressor | 4個字節的messagId值 | header數據值(2個字節的key長度 | value數據值) | 業務數據值

codec: 序列化類型:如 seata,kryo;protobuf;fst

compressor: 壓縮類型:如 NONE ,GZIP,BZIP2,LZ4

6個字節的長度:

4個字節(全部數據的長度): 默認長度16+headLength+bodyLength

2個字節的(headLength),默認長度16

業務數據序列化

io.seata.serializer.seata.SeataSerializer#serialize

2個字節(typecode的值)| body

typecode: 消息類型序編碼器 如(RegisterTMRequestCodec,BranchRollbackRequestCodec)

body:

2個字節(xid的長度)| xid的數據| 8個字節(branchId值)| 一個byte(分支事務類型ordinal值)|2個字節(ResourceId的長度)| ResourceId的值|4個字節(applicationData的長度)| applicationData的值|

事務類型: AT,TCC,XA,SAGA

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章