Netty implements RPC
Basic introduction to RPC
- RPC (Remote Procedure Call) remote procedure call means that there is a program on computer A and a program on computer B. Application A can call the method of application B. The calling method is as simple as calling its own local method.
- Commonly used RPC frameworks are: Ali's Dubbo, Google's gRPC, Spring's SpringCloud, etc.
RPC call flow
- The service consumer (Client) calls the service by local calling
- ClientStub is responsible for encapsulating methods, parameters, etc. into a message body that can be transmitted over the network after receiving the call
- ClientStub encodes the message and sends it to the server
- ServerStub receives the message and decodes it
- ServerStub calls the local service according to the decoding result
- The local service is executed and the result is returned to the ServerStub
- ServerStub will return the import result, encode it and send it to the consumer
- ClientStub receives the message and decodes it
- The service consumer (Client) gets the result
Realize dubbo RPC by yourself (based on Netty)
- The bottom layer of dubbo uses netty as the network communication framework and requires Netty to implement a simple EPC framework
- In template dubbo, consumers and providers agree on interfaces and protocols. Consumers call the provider's services remotely, the provider returns a string, and the consumer prints the data returned by the provider. The underlying network communication protocol uses Netty 4.x
Common interface
Need to define a common interface that both service providers and service consumers need