dubbo protocol message format

       Dubbo uses netty for TCP communication by default. TCP is a transport layer protocol. At the application layer, custom protocols are often extended. First, it can deal with the sticky and unpacking problem of TCP itself, and second, it can agree on other details of the communication process.

       So dubbo adopts the custom dubbo protocol by default. Document Description:

Dubbo's default protocol uses a single long connection and NIO asynchronous communication, which is suitable for small data volume and large concurrent service calls, and the number of service consumer machines is much larger than the number of service provider machines.

The default protocol is based on netty3.2.5+hessian3.2.1 interaction.
    Number of connections: single connection
    Connection method: long connection
    Transmission protocol: TCP
    Transmission method: NIO asynchronous transmission
    Serialization: Hessian binary serialization
    Scope of application: The incoming and outgoing parameter data packets are small (recommended less than 100K), and consumers are more likely to provide The number of providers is large, and a single consumer cannot overwhelm the provider. Try not to use the dubbo protocol to transmit large files or large strings.
    Applicable scenarios: conventional remote service method calls

       The processing of the byte stream in the dubbo protocol is in the com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec class, which includes the encoding and decoding of the request request and the encoding and decoding of the response response.

       The dubbo protocol uses a fixed-length message header (16 bytes) and a variable-length message body for data transmission. The message header defines some information that the communication framework netty needs when processing IO threads. The specific packet format of the dubbo protocol is as follows:

Details of the message header of the dubbo protocol message:

magic: Similar to the magic number in the java bytecode file, it is used to determine whether it is a data packet of the dubbo protocol. The magic number is the constant 0xdabb

flag: Flag bit, a total of 8 address bits. The lower four bits are used to indicate the type of serialization tool used for the message body data (hessian by default). Among the upper four bits, the first bit is 1 to indicate a request request, and the second bit is 1 to indicate two-way transmission (that is, a response is returned) , the third bit is 1, which means it is a heartbeat ping event.

status: status bit, set the status of the request response, dubbo defines some types of responses. For specific types, see com.alibaba.dubbo.remoting.exchange.Response

invoke id: message id, long type. The unique identification id of each request (due to the use of asynchronous communication, it is used to correspond the request request to the returned response)

body length: The length of the message body, int type, that is, how many bytes are recorded in the Body Content.

       Finally, I recommend an interesting website to everyone, http://asciiflow.com/. Used to do plain text drawing. The pictures in the text are drawn on this website.

       Please correct me if there is any problem in the text.

Guess you like