Because of the heterogeneity of distributed system and the diversity of distributed computing mode and task RPC as an implementation mechanism of network communication and entrusted computing came into being.

Let’s start with A scenario where services A and B are deployed on different machines. How do services A and B call each other? It would be much more productive if there was a way to invoke remote services as if they were local services, but the caller was transparent about the details of network communication, such as when a service consumer executed methodA, essentially invoking a remote service. This method is called Remote Procedure Call Protocol (RPC).

Leaving communication details aside, let’s look at the general flow of RPC calls:



1) Service consumer (Client) invocation invokes the service in a local invocation mode;

2) After receiving the call, the Client stub is responsible for assembling methods and parameters into a message body capable of network transmission;

3) The client stub finds the service address and sends the message to the server.

4) The Server Stub decodes the message after receiving it.

5) The Server Stub invokes the local service according to the decoding result;

6) The local service executes and returns the result to the server stub;

7) The Server Stub packages the returned result into a message and sends it to the consumer;

8) The Client stub receives the message and decodes it.

9) The service consumer gets the final result.



Here’s a minimalist RPC implementation:





Reference List:

www.iteye.com/blog/javata…

www.xuxueli.com/xxl-rpc/