RPC calls between service-depth understanding of

A: RPC

That RPC Remote Procedure Call (Remote Procedure Call Protocol, referred RPC), local services like call (method) as call service (method) server. The usual implementation has XML-RPC, substantially the same JSON-RPC, communication method, except that the format of the transmission data.

RPC is the core distributed architecture, by way of response following two points:

Synchronous call: the client calls the service side method, wait until the service side returns the result or a timeout, and then continue their operations

Asynchronous call: the client sends a message to the middleware, without waiting for the server to return directly to continue their operations.

There are implementations of synchronous call WebService and RMI. Services Web Service provides web-based container, the underlying use the http protocol, which calls for different languages ​​between heterogeneous systems. RMI is actually Java language RPC implementation that allows Java method returns objects and primitive data types, calls between different systems suitable for building JAVA language.

JAVA realize version asynchronous call is JMS (Java Message Service), the current open source JMS middleware has ActiveMQ Apache community, Kafka messaging middleware, and another of Ali RocketMQ.

RPC framework contains the following four components:

1, the client (Client): caller to the service

2, the client stub (Client Stub): storing the address information of the server, the client request parameters packed into a network message, and then sent to the serving network via

3, the server stub (Server Stub): receiving a message sent by the client and unpack, then call the local service

4, the server (Server): a true service provider. 

 

 

Specific implementation steps:

1, the service caller (client) (client) to invoke a local call services;

2, client stub is responsible for receiving the process parameters and the like can be assembled into a network after a call transfer message body; in Java Serialization is the process of

3, client stub find the service address, and sends a message to the server through the network;

4, server stub decoding after receiving the message, is in Java deserialization process;

5, server stub calling the local service based on the result of decoding;

6, processing logic performs local service;

7, local service returns the results to the server stub;

8, server stub packaged into the return result message, Java serialization in;

9, the message through the network server stub packaged and sent to the consumer

10, client stub receiving the message, and decoding, Java in deserialization;

11, the service caller (client) to get the final result.

RPC's goal is to 2-10 frame encapsulation step up the call, the encoding / decoding process encapsulated, allowing users to call as a local call services like remote service. To achieve the client (the caller) transparent service, RPC framework needs to consider addressing the following questions: 
1, communication problems: mainly by establishing a TCP connection between client and server, remote procedure calls all data exchanges are in this connection in the transmission. Connection can be connected on demand, after the end of the call cut off, it can be a long connection, multiple remote procedure calls to share the same connection. 
2, addressing the problem: A server application on how to tell the underlying RPC framework, how to connect to server B (such as a host or IP address) and what is the name of a specific port, the method is, in order to complete the call. For example, Web services-based protocol stack RPC, it must provide a endpoint URI, or from the UDDI lookup services. If RMI calls would also need an address to register the RMI Registry Service. 
3, the serialization and deserialization: When an application on the server A initiates a remote procedure call, parameters of the method needs to be passed as TCP to the server B through the underlying network protocol, since the network protocol is binary memory based on the parameters of the to form into a binary value of the sequence, i.e. the sequence of (the serialize) or group (Marshal), sent to the server by the address B and the transfer of the binary sequence. 
Similarly, B Parameter Set parameter server receives the deserialized. B server application calls the method to return their results should be post-treated to A serialization server, A server receives also through deserialization process.

Guess you like

Origin www.cnblogs.com/flzs/p/12174686.html