What is RPC?

The full name of RPC is Remote Procedure Call. A Remote function is called as a local function to mask the complexity of the Remote Call. Back to top Why do YOU need RPC? The development of microservices and distributed applications is becoming more and more common, and RPC can solve the service invocation and communication problems between various nodes. Governance functions such as connection management, health check, load balancing, elegant startup and shutdown, exception retries, service grouping, and fuse limiting, to name a few. Go back to the top with a full RPC

What’s the process?

  • 1. Serialization: RPC is a remote call, so data must be transmitted over the network. The caller needs to serialize the object into a transportable binary as both the request and the incoming parameters are objects.
  • 2. Data transmission: The caller transmits binary data to the service provider. By default, RPC uses TCP to transmit data because of its reliability.
  • 3. Deserialization: According to the specific protocol, the service provider can correctly split the different requests from the binary data, and reverse restore the binary message body into the request object according to the request type and serialization type.
  • 4. Method call: according to the deserialization of the request object, find the corresponding class, complete the method call.
  • 5. Return the request: Serialize the execution result and write it back to the corresponding TCP channel. After the caller gets the reply packet and deserializes it into the reply object, the caller completes an RPC call. Based on these, it can be simplified without having to focus on complex operations such as caller serialization, network transmission call, and deserialization. You can use dynamic proxy techniques, like Spring’S AOP, to intercept and enhance methods through bytecode enhancement to add the additional processing logic you need, all of which can be solved by dynamic proxy. The business interface declaration is given by the service provider. In the program of the caller, the RPC framework generates the dynamic proxy implementation class in advance according to the invoked service interface and injects it into the relevant business logic that declares the interface through dependency injection and other technologies. The proxy implementation class intercepts all method calls, completes a complete set of remote calls in the provided method processing logic, and returns the result of the remote call to the caller, so that the caller has the same experience when calling the remote method as when calling the local interface.

*

Currently commonly used RPC frameworks:

  • Dubbo: Dubbo is a distributed services framework and SOA governance solution. Its functions include high-performance NIO communication and multi-protocol integration, dynamic service addressing and routing, soft load balancing and fault tolerance, dependency analysis and degradation, etc. Dubbo is the core framework of Alibaba’s SOA service-oriented governance solution. Dubbo has been used by many non-Alibaba companies since it was open source in 2011.
  • Spring Cloud: Spring Cloud is composed of many sub-projects, such as Spring Cloud Config, Spring Cloud Netflix, Spring Cloud Consul, etc., which provides commonly used tools for building distributed systems and microservices. For example, configuration management, service discovery, circuit breakers, intelligent routing, micro proxy, control bus, one-time token, global lock, master selection, distributed session and cluster state meet all the solutions needed to build microservices. Spring Cloud is based on Spring Boot, making development and deployment extremely simple.
  • GRPC: Originally developed by Google, gRPC is a language-neutral, platform-neutral, open source remote procedure call (RPC) system.
  • Thrift: Is a lightweight cross-language RPC communication scheme that supports up to 25 programming languages.

Nodejs implements RPC principles

See github.com/cg0101/zRPC