current position:Home>Comparison between RPC service and HTTP service, Huawei finance 2021 spring recruitment interview

Comparison between RPC service and HTTP service, Huawei finance 2021 spring recruitment interview

2021-08-26 13:24:08 Programmer poison coin

Say RPC and HTTP Before the difference , I think it's necessary to understand OSI Seven layer network structure model of ( Although it is basically five layers in practical application ), It can be divided into the following layers : ( From top to bottom )

  • first floor : application layer . It defines the interface for communication and data transmission in the network ;

  • The second floor : The presentation layer . Define the transmission format of data in different systems , Coding and decoding specifications, etc ;

  • The third level : The session layer . Manage user sessions , Control the establishment and interruption of logical connections between users ;

  • The fourth level : Transport layer . Manage the end-to-end data transmission in the network ;

  • The fifth floor : The network layer . Define how data is transferred between network devices ;

  • The sixth floor : The link layer . Encapsulate the data packets of the above network layer into data frames , Easy to transport in the physical layer ;

  • The seventh floor : The physical layer . This layer is mainly to transmit these binary data .

In practice , There is no presentation layer and session layer in the five layer protocol structure . It should be said that they are merged with the application layer . We should focus on the application layer and the transport layer . because HTTP It's the application layer protocol , and TCP It's the transport layer protocol . good , After knowing the hierarchical model of the network, we can better understand why RPC Service comparison HTTP The service was better !

Two 、RPC service

1、RPC framework

This is called RPC ah ,, See light suddenly !

RPC Mainly used in large enterprises , Because there are many systems in large enterprises , Business lines are complex , And the efficiency advantage is very important , This is the time RPC The advantages are obvious , This is what we do in actual development , Projects generally use maven To manage . For example, we have a system service for processing orders , First declare all its interfaces ( This means java Medium interface), Then package the whole project into one jar package , The server side introduces this two-way library , And then realize the corresponding functions , The client side only needs to introduce this two-party library to call .

Why do you do this ? Mainly to reduce the number of clients jar Bag size , Because every time I pack and release ,jar Too many packages always affect efficiency . In addition, it decouples the client and the server , Improve code portability .

2、 Synchronous and asynchronous calls

The synchronous call is timely, and the client waits for the execution to complete and returns the result .

Asynchronous call means that the client does not wait for the call to complete and return the result , However, you can still receive the notification of the returned result through the callback function . If the client doesn't care about the results , It can be a one-way call . The process is a bit like Java Medium callable and runnable Interface , When we do asynchronous operations , If you need to know the result of execution, use callable Interface , And through Future Class gets the result information of asynchronous execution . If you don't care about the result of execution , Use it directly runnable The interface will do , Because it doesn't return results , Of course! ,callable It's OK, too , We don't go to get Future That's all right. .

3、 The popular RPC frame

Dubbo It is a very famous open source project of Alibaba group RPC frame , It is widely used in many Internet companies and enterprises . Both the protocol and the serialization framework can be pluggable . The remote interface is based on Java Interface, And rely on Spring Framework is easy to develop . Can be easily packaged into a single file , Independent process running , It is consistent with the concept of microservice .

3、 ... and 、HTTP

First line internet factory Java Core interview question bank


It's job hopping season , I sorted out some real interview questions asked by big factories , Due to the length limit of the article , Only some topics are shown to you , more Java Basics 、 abnormal 、 aggregate 、 Concurrent programming 、JVM、Spring Family bucket 、MyBatis、Redis、 database 、 middleware MQ、Dubbo、Linux、Tomcat、ZooKeeper、Netty wait … Has been collated and uploaded on my   Tencent documents 【 First line internet factory Java Core interview question bank 】 Click to collect , And will continue to update … Interested friends can see and support a wave !

copyright notice
author[Programmer poison coin],Please bring the original link to reprint, thank you.

Random recommended