New Features of Tripe 3.3

This article introduces the new features of the triple protocol in version 3.3.

Brand New REST Support

Features

In version 3.3, based on the existing HTTP protocol stack, triple implements comprehensive REST-style service export capabilities without the need for generic or gateway layer protocol conversion. Users can directly access backend Triple protocol services via HTTP protocol in a decentralized manner without configuration. It provides rich annotations and SPI extension support for advanced REST usage such as path customization, output format customization, and exception handling. Its main features include:

  • Triple Protocol Integration
    Reuses the existing HTTP protocol stack of Triple, requiring no extra configuration or new ports, supporting access to HTTP/1, HTTP/2, and HTTP/3 protocols simultaneously.
  • Decentralization
    Can expose REST APIs directly without relying on gateway applications for traffic forwarding, thus improving performance and reducing stability risks caused by gateways. Security issues can be resolved through internal application extensions, a practice validated in Taobao’s MTOP.
  • Support Existing Servlet Facilities
    Supports Servlet API and Filter, allowing users to reuse existing security components based on Servlet API. By implementing a Servlet Filter, it can integrate security frameworks like OAuth and Spring Security.
  • Multiple Dialects
    Considering that most users prefer using SpringMVC or JAX-RS for REST API development, Triple REST allows continued use of these methods to define services and supports most extension and exception handling mechanisms (with over 80% of the functionality of the original framework). For users pursuing lightweight options, the Basic dialect can be used; the out-of-the-box REST access capability of Triple is based on this dialect.
  • Strong Extendability
    Offers more than 20 extension points, enabling users to easily implement custom dialects and flexibly customize logic for parameter acquisition, type conversion, and error handling.
  • Out-of-the-Box
    REST capability is ready to use out of the box; simply enabling the Triple protocol provides REST direct access to services.
  • High-Performance Routing
    The routing part adopts optimized Radix Tree and Zero Copy technologies, enhancing routing performance.
  • Seamless Integration with OpenAPI (TBD)
    OpenAPI integration will be completed soon, providing an out-of-the-box support for exporting OpenAPI Schema. By introducing Swagger dependencies, services can be tested directly using the Web UI. With OpenAPI Schema, API tools like Postman and Apifox can be used to manage and test APIs; leveraging the OpenAPI ecosystem allows for easy cross-language calls. Future support for Schema First will be further advanced, allowing the front-end team to define OpenAPI together and generate calling code and mocks based on OpenAPI while the back-end generates stubs for service development, greatly enhancing collaborative efficiency.

Example

Example Code
  1. package org.apache.dubbo.rest.demo;
  2. import org.apache.dubbo.remoting.http12.rest.Mapping;
  3. import org.apache.dubbo.remoting.http12.rest.Param;
  4. // Service Interface
  5. public interface DemoService {
  6. String hello(String name);
  7. @Mapping(path = "/hi", method = HttpMethods.POST)
  8. String hello(User user, @Param(value = "c", type = ParamType.Header) int count);
  9. }
  10. // Service Implementation
  11. @DubboService
  12. public class DemoServiceImpl implements DemoService {
  13. @Override
  14. public String hello(String name) {
  15. return "Hello " + name;
  16. }
  17. @Override
  18. public String hello(User user, int count) {
  19. return "Hello " + user.getTitle() + ". " + user.getName() + ", " + count;
  20. }
  21. }
  22. // Model
  23. @Data
  24. public class User {
  25. private String title;
  26. private String name;
  27. }
Download and Run Example
  1. # Get the example code
  2. git clone --depth=1 https://github.com/apache/dubbo-samples.git
  3. cd dubbo-samples/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-basic
  4. # Run
  5. mvn spring-boot:run
curl Test
  1. curl -v "http://127.0.0.1:8081/org.apache.dubbo.rest.demo.DemoService/hello?name=world"
  2. # Output
  3. #> GET /org.apache.dubbo.rest.demo.DemoService/hello?name=world HTTP/1.1
  4. #>
  5. #< HTTP/1.1 200 OK
  6. #< content-type: application/json
  7. #< content-length: 13
  8. #<
  9. #"Hello world"
  10. #
  11. # Code Explanation
  12. # You can see the output "Hello world", the double quotes are because the default output content-type is application/json.
  13. # This example shows that Triple defaults to exporting services to /{serviceInterface}/{methodName} paths, supporting parameter passing via URL.
  14. curl -v -H "c: 3" -d 'name=Yang' "http://127.0.0.1:8081/org.apache.dubbo.rest.demo.DemoService/hi.txt?title=Mr"
  15. # Output
  16. #> POST /org.apache.dubbo.rest.demo.DemoService/hi.txt?title=Mr HTTP/1.1
  17. #> c: 3
  18. #> Content-Length: 9
  19. #> Content-Type: application/x-www-form-urlencoded
  20. #>
  21. #< HTTP/1.1 200 OK
  22. #< content-type: text/plain
  23. #< content-length: 17
  24. #<
  25. #Hello Mr. Yang, 3
  26. #
  27. # Code Explanation
  28. # You can see the output Hello Mr. Yang, 3, without double quotes because the suffix txt requires a text/plain output.
  29. # This example demonstrates how to customize paths with the Mapping annotation and the source of parameters with the Param annotation, which supports parameter passing through post body or URL.

Detailed Documentation

Please refer to the user manual: Tripe Rest Manual

Support for Servlet Access

In version 3.3, reusable Spring Boot servlet listening ports can access HTTP traffic without Netty listening on new ports, simplifying deployment and reducing maintenance costs. By reducing reliance on external ports, it helps easily pass through corporate firewalls and gateways, simplifying network deployment and enhancing the maintainability and security of enterprise applications.

Example

Download and Run Example
  1. # Get example code
  2. git clone --depth=1 https://github.com/apache/dubbo-samples.git
  3. cd dubbo-samples/2-advanced/dubbo-samples-triple-servlet
  4. # Run directly
  5. mvn spring-boot:run
curl Test
  1. curl --http2-prior-knowledge -v 'http://localhost:50052/org.apache.dubbo.demo.GreeterService/sayHelloAsync?request=world'
  2. # Output
  3. #* [HTTP/2] [1] OPENED stream for http://localhost:50052/org.apache.dubbo.demo.GreeterService/sayHelloAsync?request=world
  4. #* [HTTP/2] [1] [:method: GET]
  5. #* [HTTP/2] [1] [:scheme: http]
  6. #* [HTTP/2] [1] [:authority: localhost:50052]
  7. #* [HTTP/2] [1] [:path: /org.apache.dubbo.demo.GreeterService/sayHelloAsync?request=world]
  8. #>
  9. #* Request completely sent off
  10. #< HTTP/2 200
  11. #< content-type: application/json
  12. #< date: Sun, 25 Aug 2024 03:38:12 GMT
  13. #<
  14. #"Hello world"

Detailed Documentation

Please visit: how-to-enable-servlet-support-for-triple to learn how to configure and enable servlet support.

Support for HTTP/3 Protocol

Features

In version 3.3, triple implements support for the HTTP/3 protocol, allowing both RPC requests and REST requests to be transmitted via the HTTP/3 protocol. Using HTTP/3 offers the following benefits:

  • Performance Improvement
    With HTTP/3 support, latency is reduced using the QUIC protocol, speeding up request response times, especially in high-latency or complex network environments, significantly enhancing overall service performance.
  • Enhanced Reliability
    HTTP/3 avoids head-of-line blocking through multiplexing and connection migration, maintaining connection stability even in poor network conditions, ensuring reliable service delivery.
  • Improved Security
    HTTP/3 mandates TLS1.3 encryption, providing more secure communication guarantees compared to the optional encryption of traditional HTTP/2.
  • Adaptation to Weak Network Environments
    In conditions of high packet loss or unstable bandwidth, HTTP/3 can maintain high connection quality and service performance, improving performance in weak network environments.

Since HTTP/3 is based on the QUIC protocol (UDP), it may be blocked by firewalls or gateways. Therefore, triple implements HTTP/3 negotiation capabilities and enables them by default. Connections are first established via HTTP/2, and if successful and the server returns a header indicating support for HTTP/3, the client will automatically switch to HTTP/3.

Example

Download and Run Example
  1. # Get example code
  2. git clone --depth=1 https://github.com/apache/dubbo-samples.git
  3. cd dubbo-samples/2-advanced/dubbo-samples-triple-http3
  4. # Run directly
  5. mvn spring-boot:run
curl Test

Note that curl needs to be updated to a new version that supports HTTP/3, see: https://curl.se/docs/http3.html

  1. curl --http3 -vk 'https://localhost:50052/org.apache.dubbo.demo.GreeterService/sayHelloAsync?request=world'
  2. # Output
  3. #* QUIC cipher selection: TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256
  4. #* Skipped certificate verification
  5. #* using HTTP/3
  6. #* [HTTP/3] [0] OPENED stream for https://localhost:50052/org.apache.dubbo.demo.GreeterService/sayHelloAsync?request=world
  7. #* [HTTP/3] [0] [:method: GET]
  8. #* [HTTP/3] [0] [:scheme: https]
  9. #* [HTTP/3] [0] [:authority: localhost:50052]
  10. #* [HTTP/3] [0] [:path: /org.apache.dubbo.demo.GreeterService/sayHelloAsync?request=world]
  11. #>
  12. #* Request completely sent off
  13. #< HTTP/3 200
  14. #< content-type: application/json
  15. #<
  16. #"Hello world"

Performance Comparison

Impact of Packet Loss Rate on QPS

http3-qps.jpg

Impact of Packet Loss Rate on RT

http3-rt.jpg

Architecture Diagram

http3-arch.jpg

Detailed Documentation

Please visit: how-to-enable-http3-support-for-triple to learn how to configure and enable HTTP/3 support.

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)