RPC The meaning and usage of frame , What is? RPC
about RPC frame , First of all, we need to understand what is RPC, Why use RPC.
RPC Is a remote procedure call only , That is, two servers A,B,
An application deployed in A On the server , Another application is deployed in B On the server ,A The application on the server wants to call B Method provided by application on server / function , Because it is not in a memory space , Cannot call directly , The semantics of the call and the parameters of the transfer call need to be expressed through the network .
for instance , A method might be defined like this ：
Student getStudentByName(String name)
first , To solve the problem of communication , Mainly through the establishment between the client and the server TCP connect , All data exchanged during the remote call is transferred in this connection , Connection can be on demand , Close after call , also
It can be a long connection , Multiple remote calls share a connection .
second , To solve the problem of addressing , in other words ,A How does the application on the server tell the underlying RPC frame , How to connect to B The server （ Such as host or IP address ） And a specific port number , What is the name of the method , This completes the call , For example, based on WEB Of the service agreement RPC, We need to provide a endpoint
URI, Or from UDDI Find on Service . If it is RMI Call , One more RMI Registry Address to register service .
third , When A When an application on the server initiates a remote procedure call , The parameters of the method need to pass the underlying network protocol, such as TCP Pass to B The server , Because the network protocol is based on
Binary , The values of parameters in memory should be sequenced into binary form , That's serialization （Serialize） Or group (marshal), Send serialized binaries to B The server .
fourth ,B After the server receives the request , Parameters need to be deserialized （ Reverse operation of serialization ）, Revert to in memory representation , Then find the corresponding method （ Part of addressing ） Make a local call , And then get the return value .
fifth , The return value is also sent to A Application on server , Also sent serially , The server A After receiving , In deserialization , Revert to in memory representation , hand A Application on server .