Serialized data and RPC

JDK provides ObjectOutputStream and ObjectInputStream, which are used to serialize and deserialize the graphs of the basic data types of POJOs through the network .

Google 的 Protobuf

  • Support cross-platform, multi-language (support most of the current languages, such as C++, C#, Java, Python, etc.;
  • High performance and high reliability;
  • Use the protobuf compiler to automatically generate code. Protobuf uses the .proto file to describe the definition of the class, and then automatically generates the .java file based on the .proto through the protoc.exe compiler;

Custom RPC

RPC: remote procedure call, it is a technology that requests services from remote computer programs through the network without needing to understand the underlying network implementation. Common RPC frameworks include: Dubbo, Spring Cloud, grpc, etc.

  1.  The client calls the service in a local call mode.
  2. The client stub is responsible for encapsulating methods, parameters, etc. into a message body that can be transmitted over the network after receiving the call
  3. The client stub encodes the received message and sends it to the server
  4. The server stub decodes the message after receiving it
  5. The server stub calls the local service according to the decoding result
  6. The server stub will return the import result, encode it and send it to the consumer
  7. The client stub receives the message and decodes it
  8. The service consumer (client) gets the result

Design and implementation

  • Client (the caller of the service): two interfaces + a test class containing the main method
  • Client Stub: A client proxy class + a client service processing class
  • Server (service provider): two interfaces + two implementation classes
  • Server Stub: A network processing server + a server business processing class

Note: The interface of the service caller must be consistent with the interface of the service provider (the package path can be inconsistent) The
final goal to be achieved is: Call the method in HelloRPCImpl or HelloNettyImpl remotely in TestNettyRPC
 

 

Guess you like

Origin blog.csdn.net/weixin_39443483/article/details/114871983
RPC
RPC