Heavy upgrade of Dubbo Triple protocol: support for connecting Web and backend microservices via HTTP

The newly upgraded Triple protocol

In terms of microservice protocol selection, we see that more and more applications are migrating from Dubbo2 TCP binary protocol to Dubbo3 Triple protocol (compatible with gRPC) to make full use of Triple's high-efficiency, full-duplex, Streaming streaming communication model and other capabilities; the combination of Triple+HTTP/2 solves the problem of back-end service penetration, but in the practice of Ali and many community enterprises, we found that microservices based on Triple still have relatively high access costs for front-end devices, and users need to go through the gateway. Protocol conversion to access Triple backend services (similar to the previous Dubbo2 generalization call) is very costly for development testing, operation and maintenance, etc.

Based on the above background, we have fully upgraded the Triple protocol in Dubbo3: The Triple protocol is an HTTP-based RPC communication protocol specification designed by Dubbo3. It is fully compatible with the gRPC protocol, supports Request-Response, Streaming and other communication models, and can run on HTTP/1 and HTTP/2 at the same time.

You can use standard HTTP tools such as cURL to access services published by the Triple protocol.

curl \
    --header "Content-Type: application/json" \
    --data '{"sentence": "Hello Dubbo."}' \
    https://host:port/org.apache.dubbo.sample.GreetService/sayHello

Based on the Triple protocol, you can easily build a Dubbo back-end microservice system. Due to the ease-of-use design of Triple for the HTTP protocol, front-end devices such as Web, Mobile, and standard HTTP can more easily access the back-end system. At the same time, Triple is fully compatible with the gRPC protocol to achieve interoperability with the gRPC system.

The Dubbo framework provides multiple language implementations of the Triple protocol, which can help you build a browser and gRPC-compatible HTTP API interface: you only need to define a standard Protocol Buffer format service and implement business logic. Dubbo is responsible for helping to generate language-related Server Stub and Client Stub, and seamlessly connect the entire call process to Dubbo systems such as routing and service discovery. For some language versions, the Dubbo framework also provides a programming mode that is more in line with language characteristics, that is, a service definition and development mode that is not bound to IDL. For example, in Dubbo Java, you can choose to use Java Interface and Pojo class to define Dubbo services, and publish them as microservices based on Triple protocol communication.

Protocol Design Goals and Applicable Scenarios

Based on the Triple protocol, you can achieve the following goals:

When Dubbo acts as Client

Dubbo Client can access the Triple protocol service published by Dubbo server (Server), and can also access the standard gRPC server.

  • Call the standard gRPC server and send a request whose Content-type is the standard gRPC type: application/grpc, application/grpc+proto, and application/grpc+json
  • Call the Dubbo server and send a request whose Content-type is Triple: application/json, application/proto, application/triple+wrapper

When Dubbo is used as Server

By default, Dubbo Server will publish support for common HTTP and gRPC protocols at the same time, and the Triple protocol can work on HTTP/1 and HTTP/2 at the same time. Therefore, Dubbo Server can process Triple protocol requests from Dubbo clients, standard gRPC protocol requests, and HTTP requests from cURL and browsers. To distinguish by Content-type is:

  • Handle requests sent by gRPC clients whose Content-type is the standard gRPC type: application/grpc, application/grpc+proto, application/grpc+json
  • Process the content-type Triple request sent by the Dubbo client: application/json, application/proto, application/grpc+wrapper
  • Handle requests with Content-type Triple sent by cURL, browsers, etc.: application/json, application/proto, application/grpc+wrapper

example scene

According to the gRPC Spec, the Triple protocol fully supports the communication of the Content-Type: application/grpc protocol. Based on this mode, Triple Client can call any gRPC Server, and vice versa.

The Triple protocol supports a common format based on json, exposing any service to the outside, and any client that supports the standard HTTP protocol (such as cURL, browser, terminal) can directly initiate calls without any protocol conversion.

Triple supports the serialization of Java-friendly Hessian, Kryo, etc. encapsulated on top of the HTTP protocol. From the perspective of the network layer, it is a standard HTTP protocol message. It is naturally compatible with any WAF, Gateway, etc. that support the HTTP protocol, and can well reuse the infrastructure of the current network layer.

Protocol specification (Specification)

Please check the details of the Triple protocol specification Triple Specification [1] here .

Detailed relationship with the gRPC protocol

As mentioned above, Triple is fully compatible with the gRPC protocol. Since gRPC officially provides a multi-language framework implementation, why does Dubbo re-implement it through Triple? There are two core objectives:

  • First, in terms of protocol design, Dubbo designed a custom Triple protocol with reference to the two protocols gRPC and gRPC-Web: Triple is an RPC protocol based on the HTTP transport layer protocol, which is fully compatible with gRPC and can run on HTTP/1 and HTTP/2.
  • Secondly, the Dubbo framework follows the design concept in line with the positioning of the framework itself during the implementation of each language. Compared with framework libraries such as grpc-java and grpc-go, the implementation of the Dubbo protocol is simpler and purer, trying to avoid a series of problems in the official gRPC library.

gRPC itself is an excellent RPC protocol specification, but there are a series of problems in the actual use of the native gRPC library implementation, including complex implementation, binding IDL, and difficulty in debugging. Dubbo starts from practice in protocol design and implementation, and avoids these problems well:

  • The native gRPC implementation is limited by the HTTP/2 interaction specification, and cannot provide interactive methods for browsers and HTTP APIs. You need additional proxy components such as grpc-web, grpc-gateway, etc. to achieve this. In Dubbo, you can directly use curl and browser to access Triple protocol services.
  • The gRPC official library is mandatory to bind Protocol Buffers, and the only development option is to use IDL to define and manage services, which is a very heavy burden for some users who do not have strong multilingual appeal. While supporting IDL, Dubbo provides language-specific service definition and development methods for Java, Go, etc.
  • In the development stage, services published with the gRPC protocol are very difficult to debug, you can only use gRPC specific tools, and many tools are relatively crude & immature. Starting from Dubbo3, you can directly use curl | jq or Chrome developer tools to debug your service, and directly pass in the JSON structure to call the service.
  • First of all, the gRPC protocol library has a scale of more than 100,000 lines of code, but Dubbo (Go, Java, Rust, Node.js, etc.) only has a few thousand lines of code for the protocol implementation, which makes code maintenance and troubleshooting easier.
  • The gRPC implementation library provided by Google does not use mainstream third-party or official language protocol libraries, but chooses to maintain a set of implementations by itself, which makes the entire maintenance and ecological expansion more complicated. For example, grpc-go maintains a set of HTTP/2 libraries instead of the official go library used. While Dubbo uses the official library, it maintains the same performance level compared to the http protocol library maintained by gRPC itself.
  • The gRPC library only provides the implementation of the RPC protocol, and requires you to do a lot of extra work to introduce service governance capabilities into it. Dubbo itself is a microservice development framework that does not bind protocols, and the built-in HTTP/2 protocol implementation can be better connected with Dubbo's service governance capabilities.

easier to implement

The implementation of the Dubbo framework focuses on the Triple protocol itself, while the underlying network communication, HTTP/2 protocol analysis, etc. choose to rely on those network libraries that have been tested for a long time. For example, Dubbo Java is built based on Netty, while Dubbo Go is the official Go HTTP library directly used. The implementation of the Triple protocol provided by Dubbo is very simple. Corresponding to the implementation of the Protocol component in Dubbo, you can figure out the code implementation of the Dubbo protocol in just one afternoon.

Large-scale production environment inspection

Since the release of Dubbo3, the Triple protocol has been widely used in Alibaba and many community benchmarking companies, especially in some proxy and gateway interworking scenarios. On the one hand, Triple has been proven to be reliable and stable through mass production practice. On the other hand, Triple's simple, easy to debug, and non-binding IDL design are also important factors for its wide application.

Native multi-protocol support

When the Dubbo framework is used as the server to publish services, it can natively support Triple, gRPC and HTTP/1 protocols on the same port, which means that you can access the services published by the Dubbo server in various forms, and all request forms will eventually be forwarded to the same business logic implementation, which provides you with greater flexibility. Dubbo is fully compatible with the gRPC protocol and related features including streaming, trailers, error details, etc. If you choose to use the Triple protocol directly in the Dubbo framework (in addition, you can also choose to use the native gRPC protocol), then you can directly use the Dubbo client, curl, browser, etc. to access the services you publish. In terms of interoperability with the gRPC ecosystem, any standard gRPC client can normally access Dubbo services; Dubbo clients can also call any standard gRPC services, here is an example of interoperability [2] The following is an example of using the cURL client to access the Dubbo server's Triple protocol service :

curl \
    --header "Content-Type: application/json" \
    --data '{"sentence": "Hello Dubbo."}' \
    https://host:port/org.apache.dubbo.sample.GreetService/sayHello

One-stop service management access

We all know that Dubbo has rich microservice governance capabilities, such as service discovery, load balancing, traffic control, etc. This is also the advantage of using the Dubbo framework to develop applications. To use gRPC protocol communication under the Dubbo system, there are two ways to achieve it, one is to directly introduce the binary package officially released by gRPC into the Dubbo framework, and the other is to provide a source code implementation compatible with the gRPC protocol natively in Dubbo. Compared with the first method of introducing binary dependencies, the Dubbo framework natively supports the gRPC protocol through the implementation of the built-in Triple protocol. The advantage of this method is that the source code is completely controlled by itself, so the implementation of the protocol is more closely integrated with the Dubbo framework, and can be more flexibly connected to Dubbo's service governance system.

Multilingual implementation

Based on the design of the Triple protocol, we plan to provide lightweight RPC protocol implementations for as many languages ​​as possible, so that the intercommunication of the Triple protocol can completely cover multiple language stacks, and it is compatible with gRPC and has better usability. At the same time, Dubbo will continue to provide comprehensive microservice governance capabilities in some languages ​​that are widely used in microservice development (such as Java, Go, etc.), making Dubbo a set of microservice development systems that can connect front-end and back-end.

Currently, the Dubbo Java language has completed the preliminary goal of the above Triple protocol upgrade in version 3.3.0-triple-SNAPSHOT, which can be experienced in the samples/dubbo-samples-triple-unary sample (click to read the original text and jump to the sample link ) . The multi-language implementations in the synchronous advancement of the Triple protocol also include back-end implementations such as Go, Node.js, and Rust, and Javascript web-end implementations.

java language

In the Dubbo Java library implementation, in addition to the IDL method, you can use the Java Interface method to define services, which can greatly reduce the cost of using the gRPC protocol for many Java users who are familiar with the Dubbo system.

In addition, the performance of the protocol implementation of the Java version is basically the same as that of the grpc-java library, and even better than that of grpc-java in some scenarios. And all of this is based on the fact that the implementation complexity of the Dubbo version protocol is much smaller than that of the gRPC version, because grpc-java maintains a customized version of the HTTP/2 protocol implementation.

Warehouse address: https://github.com/apache/dubbo

Go language implementation

Dubbo Go recommends the IDL development mode. To generate stub code through the protoc plug-in that comes with Dubbo, you only need to provide the corresponding business logic implementation. You can access the gRPC service released by Dubbo Go through curl and browser. Warehouse address: https://github.com/apache/dubbo-go/

Rust

Dubbo Rust has fully implemented the gRPC protocol compatibility part, and is currently promoting unary RPC call support in HTTP/1 and other modes.

Warehouse address: https://github.com/apache/dubbo-rust/

Node.js

The Node.js language has fully implemented the gRPC protocol compatibility part, and is currently promoting unary RPC call support in HTTP/1 and other modes.

Warehouse address: https://github.com/apache/dubbo-js/

Web

Through the Javascript client library provided by Dubbo, you can write the front-end page running in the browser, and directly initiate a request call to the back-end Dubbo service on the browser side. Warehouse address: https://github.com/apache/dubbo-js/

Related Links:

[1] Triple Specification

https://cn.dubbo.apache.org/zh-cn/overview/reference/protocols/triple-spec/

[2] Interoperability example

https://github.com/apache/dubbo-samples/tree/triple-protocol-sample-0719/2-advanced/dubbo-samples-triple-grpc

Author: Liu Jun

Click to try cloud products for free now to start the practical journey on the cloud!

Original link

This article is the original content of Alibaba Cloud and may not be reproduced without permission.

The 8 most in-demand programming languages ​​in 2023: PHP strong, C/C++ demand slow Programmer's Notes CherryTree 1.0.0.0 released CentOS project declared "open to everyone" MySQL 8.1 and MySQL 8.0.34 officially released GPT-4 getting more and more stupid? The accuracy rate dropped from 97.6% to 2.4%. Microsoft: Intensify efforts to use Rust Meta in Windows 11 Zoom in: release the open source large language model Llama 2, which is free for commercial use. The father of C# and TypeScript announced the latest open source project: TypeChat does not want to move bricks, but also wants to fulfill the requirements? Maybe this 5k star GitHub open source project can help - MetaGPT Wireshark's 25th anniversary, the most powerful open source network packet analyzer
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/yunqi/blog/10089939