REST and RPC difference

Seven layer OSI network model

  • First layer: an application layer. It defines an interface for communication and data transmission in the network;
  • The second layer: the presentation layer. Define different transmission format encoding and decoding data system specification, and the like;
  • The third layer: the session layer. Manage user sessions controls establish a logical connection between the user and interruptions;
  • Fourth layer: the transport layer. Manages the network end to end data transmission;
  • The fifth layer: the network layer. How to transfer data between network devices is defined;
  • Sixth layer: the link layer. Above the network layer packet is encapsulated into the data frames, to facilitate physical layer transmission;
  • Seventh layer: a physical layer. This layer is the transmission of these binary data

The actual application process, which is not a five-layer structure protocol and session layer, presentation layer. It should be said that they are in the application layer merged. We should focus on the application layer and the transport layer of these two levels, because RPC is mainly based on TCP / IP protocols (Transport Protocol), HTTP is mainly based on the HTTP protocol (application layer protocol).

1. What is REST?

REST is an architectural style refers to a set of architectural constraints and principles. These applications meet the constraints and principles or design is RESTful. REST Specification as a resource to everything, and all are resources on the network. REST does not create new technologies, components or services, just use existing features and capabilities of the Web. Completely through the HTTP protocol, data communication using the HTTP protocol processing. REST architecture operations for resources, including access, create, modify, and delete the resource corresponds exactly GET, POST, PUT and DELETE method of the HTTP protocol provides.

REST HTTP verbs and style CRUD correspondence relationship:

 

2. What is RPC

Remote Procedure Call, Remote Procedure Call, is to call a remote method call local methods as the same. RPC architecture diagram:

RPC framework includes four core components are Client, Server, Client Stub and Server Stub, Stub we can understand this as a stub

  • Client (Client), caller services.
  • Server (Server), a true service provider.
  • Client stub, storing the address of the message server, the client request parameters and then packaged into a network message, and then sent to the serving network via the remote.
  • The server stub, the client receives a message sent from, the message is unpacked, and call the local method

RPC framework to do three basic things:

 How to 1) determine the function of the client-side service to be called;

    In remote call, the client and server, respectively, to maintain a [ID->] function correspondence table, ID is uniquely determined in all processes. The client when making remote procedure call, attach the ID, the server look-up table to determine the function of the client need to call, and then execute the code corresponding function.

 2) How to serialization and deserialization;

    When the client and server interaction parameters or results into byte transport streams in the network, then the need for serialization and de data into a stream of bytes or byte-stream into fixed format that can be read serialization, serialization and de-serialization of speed will affect the efficiency of remote calls.

 3) How to Internet transmission

    Most RPC frame select TCP as the transport protocol, there are some select HTTP. As gRPC use HTTP2. Different protocols have advantages and disadvantages. TCP is more efficient, more flexible and HTTP in the practical application

 

3, REST and RPC compare

4, REST and RPC application scenarios

  REST and RPC are commonly used in micro-services architecture.

  1) HTTP relatively more standardized, more standard, more general, no matter what language support http protocol. If you are open API, such as an open platform, a variety of external programming language, you can not refuse support for each language, now open source middleware, the first to support the basic agreement contains several RESTful.

 2) RPC framework as the basis of the micro-services architecture components, which can greatly reduce the micro-architecture of the service cost and improve the caller and the service provider side of the R & D efficiency, shielding all kinds of complicated cross-process call detail functions (services). Let the caller feel like calling a local function as remote function calls, enabling service providers to achieve a feeling like they were local functions to implement the service

 

5, the popular RPC framework

 1) gRPC is Google recently released open source software, based on the latest HTTP2.0 protocol, and supports many common programming languages. We know HTTP2.0 is based on a binary protocol upgraded version of HTTP, the current major browsers are supported to be at full speed. The RPC framework is based on the HTTP protocol implementation, to support the use of the underlying Netty framework.

 2)Thrift是Facebook的一个开源项目,主要是一个跨语言的服务开发框架。它有一个代码生成器来对它所定义的IDL定义文件自动生成服务代码框架。用户只要在其之前进行二次开发就行,对于底层的RPC通讯等都是透明的。不过这个对于用户来说的话需要学习特定领域语言这个特性,还是有一定成本的。

 3)Dubbo是阿里集团开源的一个极为出名的RPC框架,在很多互联网公司和企业应用中广泛使用。协议和序列化框架都可以插拔是及其鲜明的特色。同样 的远程接口是基于Java Interface,并且依托于spring框架方便开发。可以方便的打包成单一文件,独立进程运行,和现在的微服务概念一致

 

Guess you like

Origin www.cnblogs.com/renjiaqi/p/12081912.html