aboutRPC frame, First of all, we need to understand what isRPC, Why useRPC.

RPC Is a remote procedure call only, That is, two serversA,B,
An application deployed inA Server, Another application is deployed inB Server,A The application on the server wants to callB 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 serverTCP 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 underlyingRPC frame, How to connect toB The server( Such as mainframe orIP address) And a specific port number, What is the name of the method, This completes the call, For example, based onWEB Of the service agreementRPC, We need to provide aendpoint
URI, Or fromUDDI Find on Service. If it isRMI Call, One moreRMI Registry Address to register service.

  Third, WhenA When an application on the server initiates a remote procedure call, The parameters of the method need to pass the underlying network protocol, such asTCP Pass toB 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 marshalling(marshal), Send serialized binaries toB 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 toA Application on server, Also sent serially, The serverA After receiving, In deserialization, Revert to in memory representation, HandA Application on server.