I believe that through the last three articles, the basic understanding of dubbo some routines, distributed how to do, registry, admin how to play. In fact, many old iron who do not have such in-depth understanding of Dubbo will also use dubbo. But are we done just using it? Not really. Our perspective can not only satisfy the use, the deep meaning is to satisfy the underlying away and implementation mechanism.

#### (1) RPC protocol and application scenarios

In a typical RPC usage scenario, it includes service discovery, load, fault tolerance, network transmission, serialization and other components, among which THE RPC protocol specifies how the program carries out network transmission and serialization. That is to say an RPC protocol implementation is equal to a non-transparent RPC call, how to do it?

The red part goes through a thread pool. RPC cannot directly call server methods after receiving data. It must go through a thread pool. RPC protocol server in deserialization, protocol decoding, network transmission, IO operations. If the IO thread executes the business method, the business method itself needs to do a lot of operations, and the performance of the server method is very slow. As a result, the IO thread of RPC protocol will be blocked by the logic of business execution, resulting in a large number of clients blocked, and finally the link is suspended.

  • The basic components of the agreement

1. Address: service provider address 2. Port: port 3 specified by the protocol. Running the service:

  • netty
  • mina
  • RMI service
  • Servlet container (Jetty, Tomcat, Jboss)

4. Packet code: indicates the protocol packet code

  • HTTP Packet Encoding
  • Dubbo packet code

5. Serialization method:

  • Hessian2Serialization

  • DubboSerialization

  • JavaSerialization

  • JsonSerialization

#### (2) Protocol packet code

  • The HTTP protocol

  • Dubbo agreement

Protocol codec process

Dubbo protocol codec implementation process (source from Dubbo2.5.8)

1. DubboCodec. EncodeRequestData (116 l) / / code request 2. DecodeableRpcInvocation. The decode () 89 l / / decoding request 3. DubboCodec. EncodeResponseData response 4. () 184 l / / coding DecodeableRpcResult. The decode () 73 l / / decoding the response

(3) The use of RPC protocol supported in Dubbo

List of RPC protocols supported by Dubbo

Additional notes about RMI not supporting firewall penetration:

The reason is that there are two ports in the underlying RMI implementation, a fixed register port for service discovery and a random port generated for network transport. This random port cannot be set to open in advance in the firewall. Therefore, there are firewall penetration problems.

(5) Use and configuration of the protocol

The Dubbo framework supports multiple protocols for flexible extension. Users only need to configure the Dubbo: Protocol element in the Provider application.

<! -- name: Protocol name dubbo | rmi | hessian | | HTTP host: native IP don't fill in, then the system automatically obtain the port: say the system automatically choose server port, fill - 1: Run the service mina | netty | grizzy | servlet | jetty serialization: Serialization dubbo | hessian2 Java | | compactedjava | fastjson [see dubbo website for detailed configuration dubbo.io](http://dubbo.io/books/dubbo-user-book/references/xml/dubbo-protocol.html) -->

<dubbo:protocol name="dubbo" host="192.168.0.11" port="20880" server="netty"

serialization="Hessian2" charset="Utf-8" />

Copy the code
  • Demonstrates configuring Dubbo using other protocols

Dubbo protocol USES the json serialization (source see: com. Alibaba. Dubbo. RPC. The protocol. The dubbo. DubboProtocol)

Use the RMI protocol (source see: com. Alibaba. Dubbo. RPC. Protocol. The RMI. RmiProtocol) using the Http protocol (source see: Com. Alibaba. Dubbo, RPC protocol. HTTP. HttpProtocol. InternalHandler) using Heason agreement (source see: com. Alibaba. Dubbo. RPC. The protocol. The hessian. HessianProtocol. HessianHandler)

PS: Dubbo many protocols are packaged, direct XML configuration is OK, in fact, it is not complicated, for the underlying implementation is RPC communication, is nothing special socket. It is recommended to read the source code, debug trace the effect of more obvious experience.