What are the open source RPC frameworks?
One type is bound to a specific language platform, and the other type is language-independent, that is, cross-language platform.
There are mainly the following types of open source RPC frameworks bound to language platforms.
Dubbo: The earliest open source RPC framework in China, developed by Alibaba and open sourced at the end of 2011, only supports the Java language.
Motan: The RPC framework used internally by Weibo was open sourced in 2016 and only supports the Java language.
Tars: The RPC framework used internally by Tencent. It was open sourced in 2017 and only supports the C++ language.
Spring Cloud: The foreign Pivotal company’s open source RPC framework in 2014 only supports the Java language
The cross-language platform open source RPC framework mainly includes the following.
gRPC: Google’s open-source cross-language RPC framework in 2015 supports multiple languages.
Thrift: It was originally a cross-language RPC framework for internal systems developed by Facebook. In 2007, it contributed to the Apache Foundation and became one of the Apache open source projects, supporting multiple languages.
If your business scenario is limited to only one language, you can choose one of the language-bound RPC frameworks;
If it involves multiple language platforms To call each other, you should choose a cross-language platform RPC framework.
RPC framework, what are the specific differences between them?
1. Dubbo
Let’s talk about Dubbo first. Dubbo can be said to be the earliest open source RPC framework in China. Currently it only supports the Java language. Its architecture can be Use the following picture to show.
From the picture you can As you can see, Dubbo’s architecture mainly contains four roles, among which Consumer is the service consumer, Provider is the service provider, Registry is the registration center, and Monitor is the monitoring system.
The specific interaction process is that after the Consumer side obtains the Provider node through the registration center, it establishes a connection with the Provider through Dubbo’s client SDK and initiates a call. The Provider receives the Consumer’s request through Dubbo’s server SDK, and returns the result to the Consumer after processing.
2. Motan
Motan is another well-known open source RPC framework in China, and it also only supports Java language implementation. Its architecture can use the following Picture description.
Motan and Dubbo architecture Similarly, it is necessary to introduce SDK on the Client side (service consumer) and Server side (service provider). The Motan framework mainly includes the following functional modules.
register: Used to interact with the registration center, including functions such as registration service, subscription service, service change notification, and service heartbeat sending.
protocol: Used to describe the RPC service and configure the management of the RPC service. This layer can also add filters with different functions to complete functions such as statistics and concurrency restrictions.
serialize: serialize and deserialize the parameters, results and other objects in the RPC request
transport: used for remote communication, using Netty NIO’s TCP long link by default .
cluster: When requesting, an available Server will be selected according to different high availability and load balancing strategies to initiate remote calls.
3. Tars
Tars is an open source project summarized by Tencent based on years of internal practice of using microservice architecture. It only supports C++ language and its architecture The figure is as follows.
Tars’ architecture interaction is mainly Including the following processes:
Service release process: upload the server release package on the web system to patch, after the upload is successful, submit the release server request on the web, which is transmitted to the node by the registry service, and then the node pulls it Take the server’s release package to the local, and pull up the server service.
Management command process: On the web system, you can submit a management server service command request, which is transmitted by the registry service to the node service, and then the node sends the management command to the server.
Heartbeat reporting process: After the server service is running, it will periodically report the heartbeat to the node, and then the node will report the service heartbeat information to the registry service, which is managed uniformly by the registry.
Information reporting process: After the server service runs, it will regularly report statistics to stat, print remote logs to log, regularly report property information to prop, report exception information to notify, and pull service configuration information from config. .
The client access server process: the client can indirectly access the server through the object name of the server Obj, the client will pull the server routing information (such as IP, Port information) from the registry, and then according to the specific business characteristics ( Synchronous or asynchronous, TCP or UDP mode) to access the server (of course, the client can also directly access the server via IP/Port).
4. Spring Cloud
Spring Cloud uses Spring Boot features to integrate outstanding components in the open source industry, and provides a set of external microservice architecture Solutions for service governance in China.
Only the Java language platform is supported, and its architecture diagram can be described by the following diagram.
From this, Spring The Cloud microservice architecture is composed of multiple components, and the interaction process of each component is as follows.
The request to access internal services through the API gateway Zuul must be authenticated by Token first.
After passing the security certification, the gateway Zuul obtains the list of available service nodes from the registration center Eureka.
Select an available node from the available service nodes, and then distribute the request to this node.
In the entire request process, the Hystrix component is responsible for handling service timeout fusing, the Turbine component is responsible for monitoring the calls and fusing related indicators between services, the Sleuth component is responsible for call chain monitoring, and ELK is responsible for log analysis.
5. gRPC
Let’s first look at gRPC. Its principle is to define the parameters and return value types of the service interface through IDL (Interface Definition Language) files. Then the specific implementation codes of the server and the client are generated through the code generation program, so that in gRPC, the client application can call the corresponding method on another server just like calling a local object.
Its main features include three aspects.
The communication protocol uses HTTP/2, because HTTP/2 provides mechanisms for connection multiplexing, two-way streaming, server push, request priority, header compression, etc.
IDL uses ProtoBuf , ProtoBuf is a data serialization protocol developed by Google. Its compression and transmission efficiency is extremely high, and its syntax is simple. The code of the server.
6. Thrift
Look at Thrift again. Thrift is a lightweight cross-language RPC communication solution that supports up to 25 programming languages. In order to support multiple languages, like gRPC, Thrift also has its own set of interface definition language IDL. The code generator can be used to generate SDK codes for the Client and Server of various programming languages, so as to ensure that different languages can communicate with each other. Communicate with each other. Its architecture diagram can be described with the following figure.
From this picture You can see the characteristics of the Thrift RPC framework.
Support multiple serialization formats: Binary, Compact, JSON, Multiplexed, etc.
Support multiple communication methods: such as Socket, Framed, File, Memory, zlib, etc.
The server supports multiple processing methods: Simple, Thread Pool, Non-Blocking, etc.
About microservices, I have summarized a technical route and share it with you
“If you don’t accumulate steps, you can’t reach thousands of miles.” I hope you in the future can: Dreams are horses that can live everywhere! Come on, boy!
Follow the official account: “Java confidant”, update Java knowledge every day, look forward to your arrival!
Send “Interview” to receive BATJ interview materials and interview video guides.
Send “Group” to make progress with 100,000 programmers.
Send “Fun Algorithm” to receive the “Fun Algorithm” series of video tutorials.
Never send “1024”, otherwise…