Transferred from: http://www.open-open.com/lib/view/open1425797146897.html
RPC feature target
The primary function of RPC is to make it easier to build distributed computing (applications), without losing the semantic simplicity of local calls when providing powerful remote invocation capabilities.
To achieve this goal, the RPC framework needs to provide a transparent calling mechanism so that the consumer does not have to explicitly differentiate between local calls and remote calls
RPC Call Classification:
RPC calls can be divided into two types:
1) Synchronous invocation: Client waits for call execution to complete and returns execution result
2) Asynchronous invocation: Client calls do not wait for the execution result to return, but can still get execution result by callback method
RPC Fabric Disassembly
RPC provider through the Rpcserver export (exported) remote interface method, RPC client side via Rpcclient import (imported) Remote interface method
Client side:
Call the remote interface method like the local method, the RPC framework implements the proxy implementation of the interface, and the actual invocation is delegated to the proxy rpcproxy
The proxy prcproxy encapsulates the call information and transfers the call to Prcinvoker to actually execute
The client's rpcinvoker through the connector Rpcconnector maintains the channel Rpcchannel with the server, uses Prcprotocol to execute the protocol encoding, and sends the encoded request message through the channel to the Service party
Service party:
Accepts the client's call request through the receiver Rpcacceptor, and also uses RpcProtocol to perform the protocol decoding
The decoded call message is passed to the Rpcprocessor to control the processing of the call procedure
Finally delegate to Prcinvoker to actually execute the call and put back the execution result
Responsibility planning for each component:
- Rpcserver
Responsible for exporting the Remote Interface (export)
- Rpcclient
The proxy implementation that is responsible for importing (import) the remote interface
- RpcProxy
Proxy implementations of remote interfaces
- Rpcinvoker
Client-side implementation: Responsible for encoding call information and sending call requests to the service party and waiting for the call result to return
Service-Side implementation: Responsible for invoking the specific implementation of the server-side interface and returning the result of the call
- RpcProtocol
Responsible for protocol compilation/decoding
- Rpcconnector
Responsible for maintaining the connection channel between the client and the service party and sending the data to the service party
- Rpcacceptor
Responsible for receiving client requests and returning request results
- Rpcprocessor
Responsible for controlling the call process in the service side, including managing the call thread pool, time-out, etc.
- Rpcchannel
Data transmission Channel
(go) RPC principle detailed