Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of RPC framework?

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the principle of RPC framework". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the principle of RPC framework".

What is RPC?

RPC is a framework or architecture whose main goal is to make remote service invocation easier and transparent, invoking remotely as if it were local.

Baidu encyclopedia explains:

RPC (Remote Procedure Call)-remote procedure call, which is a protocol that requests services from remote computer programs over the network without knowing the underlying network technology. The RPC protocol assumes the existence of certain transport protocols, such as TCP or UDP, to carry information data between communication programs. In the OSI network communication model, RPC spans the transport layer and the application layer. RPC makes it easier to develop applications, including web-based distributed multiprograms.

Under what circumstances do I use RPC?

If we develop simple applications, the business process is simple, the traffic is small, and there is no need for RPC at all.

When our application traffic and business increase, we find that the stand-alone machine can no longer bear it. At this time, we can split it into several unrelated applications according to different businesses (clear division of business logic) and deploy them on different machines. RPC may not be needed at this time.

With more and more business, more and more applications, applications and applications are related to each other, and it is found that some functions can no longer be simply divided, so RPC may be needed at this time.

For example, when we develop an e-commerce system, we need to split user service, commodity service, coupon service, payment service, order service, logistics service, after-sales service and so on. These services are all called with each other. It is best to use RPC for internal invocation. At the same time, each service can be deployed and launched independently.

In other words, when our project is too large, need to decouple services, strong scalability, flexible deployment, we need to use RPC, mainly to solve the problem of service-to-service invocation in the distributed system.

Principle of RPC framework

The RPC architecture mainly consists of three parts:

The service registry (Registry) is responsible for publishing local services as remote services, managing remote services and providing them to service consumers.

A service provider (Server) that provides service interface definitions and service implementation classes.

A service consumer (Client) that invokes a remote service through a remote proxy object.

After startup, the service provider actively registers the machine IP, ports and the list of services provided with the service registry (Registry)

At startup, the service consumer obtains a list of service provider addresses from the service registry (Registry).

The service registry (Registry) enables load balancing and failover.

RPC calling procedure

(1) the client (client) invokes the service locally

(2) after receiving the call, the client client stub is responsible for assembling methods, parameters, etc., into a message body that can be transmitted over the network (serializing the message body object into binary)

(3) the client sends the message to the server through sockets

(4) the server stub (server stub) decodes the message after receiving it (deserializes the message object)

(5) the server stub (server stub) calls the local service according to the decoding result

(6) execute the local service and return the result to the server stub (server stub)

(7) the server stub (server stub) packages the returned result into a message (serializes the result message object)

(8) the server (server) sends messages to the client through sockets

(9) the client stub (client stub) receives and decodes the result message (serializes the result message)

(10) the client (client) gets the final result.

RPC is meant to encapsulate steps 2, 3, 4, 7, 8, and 9.

Advantages of RPC

Cross-language (C++, PHP, Java, Python...)

The protocol is private and secure.

High efficiency of data transmission

Support for dynamic expansion

Shortcomings of RPC

It is difficult to develop a perfect RPC framework, which needs more professionals and is more difficult for beginners.

Thank you for your reading, the above is the content of "what is the principle of RPC framework". After the study of this article, I believe you have a deeper understanding of what the principle of RPC framework is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report