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 RPC?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces what is RPC, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

What is RPC?

When it comes to RPC (Remote Procedure Call), you can't avoid mentioning distribution, the field that led to the birth of RPC.

Suppose you have a Calculator and its implementation class CalculatorImpl, then when a single application calls the add method of Calculator to perform an addition operation, you can use it directly in the method, because in the same address space, or in the same block of memory, this is called a local function call.

Now, the system is transformed into a distributed application, and the interface call and implementation are in two subsystems.

There is no CalculatorImpl class in Service A, so how does it invoke the add method of Service B's CalculatorImpl? You can mimic the invocation method of the Bachet S architecture by exposing a Restful interface in B service, and then A service invokes the add method of CalculatorImpl indirectly by calling this Restful interface.

In this way, it is very close to RPC, but do you need to write a string of code to initiate a http request with each call like this? Like httpClient.sendRequest.... Can you simply initiate a remote call, like a local method call, so that the user is not aware of the process of the remote call?

The shielding work can be solved by using the proxy pattern to generate a proxy object, and the interior of the proxy object is to implement the RPC remote procedure call through httpClient.

These are the problems and ideas to be solved by many RPC frameworks, such as Ali's Dubbo.

To sum up, there are two issues that RPC wants to solve:

1. Solve the problem of invocation between services in distributed systems.

two。 Remote calls should be as convenient as local calls, so that the caller is not aware of the logic of the remote call.

RPC is a conceptual term for technology.

RPC=Remote Produce Call is a concept of technology, and HTTP is a protocol. RPC can be implemented through HTTP or through a set of protocols implemented by Socket itself. So the title can be changed to understand why RPC has an implementation other than HTTP. Why is it necessary? after all, private protocols are not universal except for HTTP implementation.

Benefits of RPC framework

Http interface is a communication means commonly used to solve the information isolated island at the initial stage when there are not many interfaces and there is little interaction between the system and the system.

The advantage is simple, direct and convenient for development.

If it is a large website with many internal subsystems and many interfaces, the benefits of the RPC framework are shown:

First of all, there are long links, so you don't have to shake hands three times like http every time, which reduces the network overhead.

Secondly, RPC frameworks generally have a registration center and rich monitoring and management; release, offline interface, dynamic expansion and so on, are imperceptible and unified operations for callers.

* is security.

Rpc is a concept, and http is also a way of implementing rpc.

In terms of complexity, dubbo/hessian is super easy to use.

As for why you use dubbo/hessian, there are a few points:

First, the call is simple, which really provides the function of calling the interface similar to calling the local method.

Second, the return value of the parameter is simple and clear that the parameter and the return value are directly defined in the jar package and do not need to be parsed twice.

Third, it is lightweight and has no superfluous information.

Fourth, the registration center is easy to manage and based on dubbo.

RPC can decouple services

RPC: remote procedure call. The core of RPC is not what protocol to use. The purpose of RPC is to allow you to call remote methods locally, but this call is transparent to you, and you don't know where the calling method is deployed.

Services can be decoupled through RPC, which is the real purpose of using RPC. The principle of RPC mainly uses the dynamic proxy mode, but as for the http protocol, it is only a transport protocol. Simple implementations can refer to spring remoting, and complex implementations can refer to dubbo.

Rpc=socket + dynamic agent

The principle of server communication is that one socket server An and another socket client B are now written or read directly in stream if you want to communicate. This enables communication, but there is a problem. How to know more information?

For example, need to send stream size, coding, Ip and so on. In this way, there is a protocol, and the protocol is the specification, that is, the sent stream carries a lot of content. Then go back to the question. The content sent is the text type, and the client has to be serialized, so there are commonly used things like json,xml, and if you want to make the content smaller, you have binary. Turn the text into binary transfer.

When it comes to the interface between rpc and http, don't be too complicated. The rpc protocol is simpler and smaller, so it is a little more efficient.

What is rpc? It is socket plus dynamic agent.

Thank you for reading this article carefully. I hope the article "what is RPC" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report