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:
public interface DemoService {
String sayHello(String name);
}
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
kubectl apply -f https://raw.githubusercontent.com/apache/dubbo-samples/master/2-advanced/dubbo-samples-gateway/dubbo-samples-gateway-higress/dubbo-samples-gateway-higress-triple/deploy/nacos/Nacos.yaml
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:
kubectl apply -f https://raw.githubusercontent.com/apache/dubbo-samples/master/2-advanced/dubbo-samples-gateway/dubbo-samples-gateway-higress/dubbo-samples-gateway-higress-triple/deploy/provider/Deployment.yaml
The specific deployment file definition is as follows:
apiVersion: apps/v1
kind: Deployment
metadata:
name: gateway-higress-triple-provider
namespace: default
labels:
app: gateway-higress-triple-provider
spec:
replicas: 1
selector:
matchLabels:
app: gateway-higress-triple-provider
template:
metadata:
labels:
app: gateway-higress-triple-provider
spec:
containers:
- name: gateway-higress-triple-provider
image: docker.io/allenyi/higress-triple:2.0.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 50052
env:
- name: NACOS_ADDRESS
value: nacos-server.default.svc.cluster.local
Higress can interface with Nacos as a service source through McpBridge. Apply the following resources in the K8s cluster to configure McpBridge:
kubectl apply -f https://raw.githubusercontent.com/apache/dubbo-samples/master/2-advanced/dubbo-samples-gateway/dubbo-samples-gateway-higress/dubbo-samples-gateway-higress-triple/deploy/mcp/mcpbridge.yaml
The specific definition of the installed McpBridge resource is as follows:
apiVersion: networking.higress.io/v1
kind: McpBridge
metadata:
name: nacos-service-resource
namespace: higress-system
spec:
registries:
- domain: nacos-server.default.svc.cluster.local
nacosGroups:
- DEFAULT_GROUP
name: nacos-service-resource
port: 8848
type: nacos2
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:
kubectl apply -f https://raw.githubusercontent.com/apache/dubbo-samples/master/2-advanced/dubbo-samples-gateway/dubbo-samples-gateway-higress/dubbo-samples-gateway-higress-triple/deploy/ingress/Ingress.yaml
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:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
higress.io/destination: gateway-higress-triple-provider.DEFAULT-GROUP.public.nacos
name: demo
namespace: default
spec:
ingressClassName: higress
rules:
- http:
paths:
- backend:
resource:
apiGroup: networking.higress.io
kind: McpBridge
name: default
path: /org.apache.dubbo.samples.gateway.api.DemoService
pathType: Prefix
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:
$ curl "localhost/org.apache.dubbo.samples.gateway.api.DemoService/sayHello?name=HigressTriple"
"Hello HigressTriple"
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:
@RequestMapping("/triple/demo")
public interface DemoService {
@RequestMapping(method = RequestMethod.GET, value = "/hello")
String sayHello(@RequestParam("name") String name);
}
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
:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
higress.io/destination: gateway-higress-triple-provider.DEFAULT-GROUP.public.nacos
name: demo
namespace: default
spec:
ingressClassName: higress
rules:
- http:
paths:
- backend:
resource:
apiGroup: networking.higress.io
kind: McpBridge
name: default
path: /triple/demo
pathType: Prefix
The service can be accessed using /triple/demo/hello
:
$ curl "localhost/triple/demo/hello?name=HigressTriple"
"Hello HigressTriple"