In the triple protocol specification, we detailed the friendly design of the triple protocol for browsers and gateways, one very important aspect being that triple supports running on both HTTP/1 and HTTP/2:
application/json
, application/yaml
, etc.Next, let’s see how to quickly access the backend triple microservice system through some common gateway products for frontend HTTP traffic.
http -> dubbo
protocol conversion, etc. Any mainstream gateway device can directly access the backend triple protocol service through HTTP traffic.
Refer to Publishing REST Style ServicesAs illustrated, HTTP requests from browsers, phones, or web servers can be directly forwarded by the gateway to backend Dubbo services, while backend services continue to use the triple binary protocol. Since the traffic entering and exiting the gateway is standard HTTP, there is no need for the gateway to perform any proprietary protocol conversion work, nor any custom logic, allowing it to focus solely on traffic routing and responsibilities.
In a real production environment, the only issue that the gateway needs to address is service discovery: how to dynamically perceive changes in backend triple service instances? The good news is that several mainstream open-source gateway products, such as Apache APISIX and Higress, generally support using Nacos, Zookeeper, Kubernetes as upstream data sources.
Next, we will detail the workflow of the entire mechanism using a typical example of Higress + Nacos + Dubbo
.
The complete source code for this example can be found at dubbo-samples-gateway-higress-triple.
In this example, a triple service defined as org.apache.dubbo.samples.gateway.api.DemoService
is defined and published:
Next, we demonstrate how to start the Dubbo service and use the Higress gateway to forward requests to the backend service.
Next, we will specifically demonstrate the steps for accessing the Higress gateway, including deploying the Dubbo application, Nacos registry, and Higress gateway.
The following example is deployed in a Kubernetes environment, so ensure you are connected to a usable Kubernetes cluster.
Install Higress, refer to the Higress Deployment Documentation.
Install Nacos by running
After packaging the above example application into a Docker image (using the pre-packaged official example image), start the application in standard Kubernetes Deployment format:
The specific deployment file definition is as follows:
Higress can interface with Nacos as a service source through McpBridge. Apply the following resources in the K8s cluster to configure McpBridge:
The specific definition of the installed McpBridge resource is as follows:
For more detailed configuration, refer to McpBridge Configuration Documentation.
Next, we create the following Ingress to create an HTTP route pointing to the Dubbo service:
Thus, requests with the path prefix /org.apache.dubbo.samples.gateway.api.DemoService
will be routed to the Dubbo service we just created.
The specific resource definitions of the installed resources are as follows:
Note here that the annotation higress.io/destination specifies the target service to which the route should ultimately be forwarded: gateway-higress-triple-provider
, which is the name of the application that just started the Dubbo service (relying on the application-level address list registered by Dubbo3).
For services sourced from Nacos, the format here is: “ServiceName.ServiceGroup.NamespaceID.nacos”. Note that the underscore ‘_’ in the service group is converted to a dash ‘-’. When the namespace is not specified, the default value here is “public”.
For more traffic governance-related configurations, refer to Ingress Annotation Configuration Documentation and Advanced Traffic Governance through Ingress Annotation.
You can access Higress using cURL to call the backend triple service:
kubectl port-forward service/higress-gateway -n higress-system 80:80 443:443
to expose Higress in the cluster for access.The access path exposed directly through the Java path name and method, such as /org.apache.dubbo.samples.gateway.api.DemoService/sayHello/
, while easily callable, is not user-friendly for the front end. Next, let’s see how to publish a REST-style HTTP service.
In the previous example, something like http://127.0.0.1:9080/triple/demo/hello
would be a more frontend-friendly access method. To achieve this, we can configure uri rewrite in gateways such as Higress, thereby mapping the frontend /triple/demo/hello
to the backend /org.apache.dubbo.samples.gateway.api.DemoService/sayHello/
.
In addition to reconfiguring the gateway rewrite rules, the Dubbo framework also provides built-in support for exposing REST-style HTTP access paths for triple services. The specific usage depends on whether you are using protobuf-based service definition mode or Java interface-based service definition mode:
By adding any of the following annotations to the Java interface, you can publish both triple binary and REST-style services. With this configuration, for the same service, you can access it using standard binary triple format or via REST HTTP in JSON format.
Spring Web style annotations:
Regarding the interface annotations:
At this point, our route prefix configuration is as follows, maintaining the previous Nacos address configuration, while changing the path prefix to a friendlier /triple/demo
:
The service can be accessed using /triple/demo/hello
: