dubbo网络通讯层协议浅析。
开始是com.alibaba.dubbo.remoting.transport.netty.NettyServer监听tcp
然后dubbo将ByteBuffer 封装成ChannelBufferInputStream InputStream子类
com.alibaba.dubbo.rpc.protocol.dubbo.DubboCodec#decodeBody
开始协议解析
int readable = buffer.readableBytes(); byte[] header = new byte[Math.min(readable, HEADER_LENGTH)]; buffer.readBytes(header);
前面 16个字节为头信息
if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW)
int len = Bytes.bytes2int(header, 12);
long id = Bytes.bytes2long(header, 4);
byte flag = header[2], proto = (byte) (flag & SERIALIZATION_MASK); Serialization s = CodecSupport.getSerialization(channel.getUrl(), proto);
flag是用来确定协议的,和选择用那种序列化的
dubbo是用Hessian2Serialization来序列化的
status是用来标识成功失败的
最后到
com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation#decode(com.alibaba.dubbo.remoting.Channel, java.io.InputStream)来具体解析对象
setAttachment(Constants.DUBBO_VERSION_KEY, in.readUTF()); setAttachment(Constants.PATH_KEY, in.readUTF()); setAttachment(Constants.VERSION_KEY, in.readUTF());
设置相关值
com.alibaba.com.caucho.hessian.io.Hessian2Input#readObject()
这个方法可以看到dubbo如何从字节中解析出一个具体的对象。
后面有时间再具体深入分析吧。