Magic - Magic High & Magic Low (16 bits)
Identifies the protocol version number, Dubbo Protocol: 0xdabb
Req/Res (1 bit)
Indicates whether it is a request or response. Request: 1; Response: 0.
2 Way (1 bit)
Only useful when Req/Res is 1 (request), marks whether a return value is expected from the server. Set to 1 if a return value from the server is needed.
Event (1 bit)
Indicates whether it is an event message, such as a heartbeat event. Set to 1 if this is an event.
Serialization ID (5 bit)
Identifies the serialization type: for example, the value for fastjson is 6.
Status (8 bits)
Only useful when Req/Res is 0 (response), used to identify the response status.
Request ID (64 bits)
Identifies a unique request. Type is long.
Data Length (32 bits)
Length of the serialized content (variable part), counted in bytes. Type is int.
Variable Part
Each part serialized by a specific serialization type (identified by Serialization ID) is a byte[] or byte.
Note: For the (Variable Part), the current version of the Dubbo framework adds additional newline characters as separators between each content part when using JSON serialization, please add an extra newline after each part of the Variable Part, for example:
Dubbo version bytes (newline)
Service name bytes (newline)
...
Unfriendly for gateway proxy components. For HTTP requests, the resource to be accessed can be determined through headers, while Dubbo requires specific serialization protocols to resolve service names, methods, and method signatures. These locators are string types or string arrays, easily convertible to bytes and could be assembled into headers. Similar to HTTP/2 header compression, an int could be negotiated to identify RPC call resources, improving performance; if resource locators were assembled in the header
, this functionality would be easier to implement.
Using req/res to determine if it is a request, the protocol can be fine-tuned, removing unnecessary identifiers and adding specific identifiers. For instance, status
and twoWay
identifiers can be strictly customized, removing redundant identifiers. Additionally, timeout is transmitted as a Dubbo attachment
, theoretically it should be placed in the request protocol’s header since timeout is essential in network requests. Noting attachment
, it can be seen that some fields in attachment
duplicate existing fields in the protocol content
, such as path
and version
, which increases protocol size.
Dubbo converts the service name com.alibaba.middleware.hsf.guide.api.param.ModifyOrderPriceParam
to Lcom/alibaba/middleware/hsf/guide/api/param/ModifyOrderPriceParam;
, which is unnecessary, adding only a ;
would suffice.
The Dubbo protocol does not reserve extension fields, making it difficult to add new identifiers, thus affecting extensibility. For example, adding response context
functionality can only be done by updating the protocol version number, which requires both the client and server versions to be upgraded, making it unfriendly for distributed scenarios.