Skip to content

Commit d48d7cf

Browse files
authored
feat: migrate apisix sample (#1023)
* feat: migrate apisix sample * add link
1 parent b97e7be commit d48d7cf

File tree

28 files changed

+769
-576
lines changed

28 files changed

+769
-576
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A collection of runnable Dubbo-go examples covering configuration, registries, o
1111
### Samples
1212

1313
* `async`: Callback (asynchronous) and one-way RPC examples.
14+
* `apisix`: Example integrating Apache APISIX with Dubbo-go.
1415
* `book-flight-ai-agent`: Example of booking flights using an AI agent.
1516
* `config_center`: Demonstrates how to use different config centers (e.g., Nacos, Zookeeper) for configuration management.
1617
* `config_yaml`: Shows how to configure Dubbo-go applications using YAML files.
@@ -49,7 +50,6 @@ A collection of runnable Dubbo-go examples covering configuration, registries, o
4950

5051
### compatibility (legacy Dubbo-go samples)
5152

52-
* `compatibility/apisix`: Example integrating Apache APISIX with Dubbo-go.
5353
* `compatibility/generic`: Generic invocation example.
5454
* `compatibility/polaris`: Dubbo-go integrate with polaris samples.
5555
* `compatibility/polaris/limit`: Quickly experience Polaris' service current limiting capabilities in dubbogo

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### 示例
1212

1313
* `async`:回调(异步)与单向 RPC 调用示例。
14+
* `apisix`:Dubbo-go 集成 Apache APISIX 的示例。
1415
* `book-flight-ai-agent`:使用 AI Agent 实现机票预订的示例。
1516
* `config_center`:演示如何使用不同配置中心(如 Nacos、Zookeeper)进行配置管理。
1617
* `config_yaml`:展示如何使用 YAML 文件配置 Dubbo-go 应用。
@@ -49,7 +50,6 @@
4950

5051
### compatibility(旧版 Dubbo-go 示例)
5152

52-
* `compatibility/apisix`:Dubbo-go 集成 Apache APISIX 的示例。
5353
* `compatibility/generic`:泛化调用示例。
5454
* `compatibility/polaris`: Dubbo-go 与 polaris 集成示例.
5555
* `compatibility/polaris/limit`: 在 dubbogo 中快速体验北极星的服务限流能力

apisix/README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# APISIX Integration with Dubbo-Go
2+
3+
[English](README.md) | [中文](README_zh.md)
4+
5+
This example demonstrates how to use Apache APISIX as an API gateway for Dubbo-Go services.
6+
7+
## Overview
8+
9+
Apache APISIX is a dynamic, real-time, high-performance API gateway. This example shows how to:
10+
- Create Triple protocol services using Dubbo-Go 3.x new API
11+
- Use Nacos for service registration and discovery
12+
- Use APISIX gateway for HTTP to gRPC/Triple protocol conversion
13+
- Access Dubbo-Go services through APISIX routes
14+
15+
## Requirements
16+
17+
- Linux or macOS
18+
- Docker 20.10+
19+
- Docker Compose v2.0+
20+
- Go 1.18+ (for local development)
21+
22+
## Architecture
23+
24+
```
25+
Client (HTTP) -> APISIX Gateway -> Dubbo-Go Service (Triple/gRPC)
26+
↓ ↓
27+
etcd Nacos Registry
28+
```
29+
30+
## Quick Start
31+
32+
### 1. Create Docker Network
33+
34+
```bash
35+
docker network create default_network
36+
```
37+
38+
### 2. Start Dependencies
39+
40+
Start etcd, MySQL, Nacos, and APISIX in order:
41+
42+
```bash
43+
# Start etcd (APISIX configuration center)
44+
cd ./deploy/etcd-compose
45+
docker compose up -d
46+
47+
# Start MySQL (Nacos database)
48+
cd ../mysql5.7-compose
49+
docker compose up -d
50+
51+
# Wait for MySQL to be ready (~10 seconds)
52+
sleep 10
53+
54+
# Start Nacos
55+
cd ../nacos2.0.3-compose
56+
docker compose up -d
57+
58+
# Wait for Nacos to be ready (~20 seconds)
59+
sleep 20
60+
61+
# Start APISIX (API gateway)
62+
cd ../apisix-compose
63+
docker compose up -d
64+
65+
cd ../../
66+
```
67+
68+
### 3. Build and Start Dubbo-Go Service
69+
70+
```bash
71+
# Build image
72+
./build.sh
73+
74+
# Get Nacos container IP
75+
NACOS_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nacos)
76+
77+
# Start Dubbo-Go service
78+
docker run -d \
79+
--name dubbo-go-apisix-server \
80+
--network default_network \
81+
-e NACOS_ADDR=$NACOS_IP:8848 \
82+
dubbo-go-apisix-server:latest
83+
```
84+
85+
### 4. Configure APISIX
86+
87+
#### 4.1 Configure Protocol Buffer
88+
89+
```bash
90+
curl -X PUT 'http://127.0.0.1:80/apisix/admin/proto/1?api_key=edd1c9f034335fi23f87ad84b625c8f1' \
91+
-H 'Content-Type: application/json' \
92+
-d '{
93+
"content": "syntax = \"proto3\";\npackage helloworld;\n\noption go_package = \"github.com/apache/dubbo-go-samples/apisix/proto;greet\";\n\nservice Greeter {\n rpc SayHello (HelloRequest) returns (User) {}\n rpc SayHelloStream (stream HelloRequest) returns (stream User) {}\n}\n\nmessage HelloRequest {\n string name = 1;\n}\n\nmessage User {\n string name = 1;\n string id = 2;\n int32 age = 3;\n}"
94+
}'
95+
```
96+
97+
#### 4.2 Configure Route
98+
99+
```bash
100+
curl -X PUT 'http://127.0.0.1:80/apisix/admin/routes/1?api_key=edd1c9f034335fi23f87ad84b625c8f1' \
101+
-H 'Content-Type: application/json' \
102+
-d '{
103+
"uri": "/helloworld",
104+
"name": "helloworld",
105+
"methods": ["GET", "POST"],
106+
"plugins": {
107+
"grpc-transcode": {
108+
"method": "SayHello",
109+
"proto_id": "1",
110+
"service": "helloworld.Greeter"
111+
}
112+
},
113+
"upstream": {
114+
"type": "roundrobin",
115+
"scheme": "grpc",
116+
"discovery_type": "nacos",
117+
"pass_host": "pass",
118+
"service_name": "dubbo_apisix_server"
119+
},
120+
"status": 1
121+
}'
122+
```
123+
124+
### 5. Test
125+
126+
```bash
127+
curl 'http://127.0.0.1:80/helloworld?name=World'
128+
```
129+
130+
Expected output:
131+
132+
```json
133+
{
134+
"age": 21,
135+
"id": "12345",
136+
"name": "Hello World"
137+
}
138+
```
139+
140+
## Verify Service Registration
141+
142+
Access Nacos console to check service registration:
143+
144+
```
145+
http://localhost:8848/nacos
146+
Username: nacos
147+
Password: nacos
148+
```
149+
150+
You should see the `providers:helloworld.Greeter::` service in the service list.
151+
152+
## References
153+
154+
- [Apache APISIX Documentation](https://apisix.apache.org/docs/apisix/getting-started)
155+
- [Dubbo-Go Documentation](https://dubbogo.apache.org/)
156+
- [Nacos Documentation](https://nacos.io/)

apisix/README_zh.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# APISIX 整合 Dubbo-Go
2+
3+
[English](README.md) | [中文](README_zh.md)
4+
5+
本示例演示如何使用 Apache APISIX 作为 Dubbo-Go 服务的 API 网关。
6+
7+
## 概述
8+
9+
Apache APISIX 是一个动态、实时、高性能的 API 网关,本示例展示了如何:
10+
- 使用 Dubbo-Go 3.x 的新 API 创建 Triple 协议服务
11+
- 通过 Nacos 进行服务注册与发现
12+
- 使用 APISIX 网关进行 HTTP 到 gRPC/Triple 的协议转换
13+
- 通过 APISIX 路由访问 Dubbo-Go 服务
14+
15+
## 环境要求
16+
17+
- Linux 或 macOS
18+
- Docker 20.10+
19+
- Docker Compose v2.0+
20+
- Go 1.18+ (如需本地开发)
21+
22+
## 架构说明
23+
24+
```
25+
Client (HTTP) -> APISIX Gateway -> Dubbo-Go Service (Triple/gRPC)
26+
↓ ↓
27+
etcd Nacos Registry
28+
```
29+
30+
## 快速开始
31+
32+
### 1. 创建 Docker 网络
33+
34+
```bash
35+
docker network create default_network
36+
```
37+
38+
### 2. 启动依赖服务
39+
40+
按顺序启动 etcd、MySQL、Nacos 和 APISIX:
41+
42+
```bash
43+
# 启动 etcd (APISIX 的配置中心)
44+
cd ./deploy/etcd-compose
45+
docker compose up -d
46+
47+
# 启动 MySQL (Nacos 的数据库)
48+
cd ../mysql5.7-compose
49+
docker compose up -d
50+
51+
# 等待 MySQL 启动完成 (约10秒)
52+
sleep 10
53+
54+
# 启动 Nacos
55+
cd ../nacos2.0.3-compose
56+
docker compose up -d
57+
58+
# 等待 Nacos 启动完成 (约20秒)
59+
sleep 20
60+
61+
# 启动 APISIX (API 网关)
62+
cd ../apisix-compose
63+
docker compose up -d
64+
65+
cd ../../
66+
```
67+
68+
### 3. 构建并启动 Dubbo-Go 服务
69+
70+
```bash
71+
# 构建镜像
72+
./build.sh
73+
74+
# 获取 Nacos 容器 IP
75+
NACOS_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nacos203-compose-nacos-1)
76+
echo $NACOS_IP
77+
78+
# 启动 Dubbo-Go 服务
79+
docker run -d \
80+
--name dubbo-go-apisix-server \
81+
--network default_network \
82+
-e NACOS_ADDR=$NACOS_IP:8848 \
83+
dubbo-go-apisix-server:latest
84+
```
85+
86+
### 4. 配置 APISIX
87+
88+
#### 4.1 配置 Protocol Buffer
89+
90+
```bash
91+
curl -X PUT 'http://127.0.0.1:80/apisix/admin/proto/1?api_key=edd1c9f034335fi23f87ad84b625c8f1' \
92+
-H 'Content-Type: application/json' \
93+
-d '{
94+
"content": "syntax = \"proto3\";\npackage helloworld;\n\noption go_package = \"github.com/apache/dubbo-go-samples/apisix/proto;greet\";\n\nservice Greeter {\n rpc SayHello (HelloRequest) returns (User) {}\n rpc SayHelloStream (stream HelloRequest) returns (stream User) {}\n}\n\nmessage HelloRequest {\n string name = 1;\n}\n\nmessage User {\n string name = 1;\n string id = 2;\n int32 age = 3;\n}"
95+
}'
96+
```
97+
98+
#### 4.2 配置路由
99+
100+
```bash
101+
curl -X PUT 'http://127.0.0.1:80/apisix/admin/routes/1?api_key=edd1c9f034335fi23f87ad84b625c8f1' \
102+
-H 'Content-Type: application/json' \
103+
-d '{
104+
"uri": "/helloworld",
105+
"name": "helloworld",
106+
"methods": ["GET", "POST"],
107+
"plugins": {
108+
"grpc-transcode": {
109+
"method": "SayHello",
110+
"proto_id": "1",
111+
"service": "helloworld.Greeter"
112+
}
113+
},
114+
"upstream": {
115+
"type": "roundrobin",
116+
"scheme": "grpc",
117+
"discovery_type": "nacos",
118+
"pass_host": "pass",
119+
"service_name": "dubbo_apisix_server"
120+
},
121+
"status": 1
122+
}'
123+
```
124+
125+
### 5. 测试
126+
127+
```bash
128+
curl 'http://127.0.0.1:80/helloworld?name=World'
129+
```
130+
131+
预期输出:
132+
133+
```json
134+
{
135+
"age": 21,
136+
"id": "12345",
137+
"name": "Hello World"
138+
}
139+
```
140+
141+
## 验证服务注册
142+
143+
访问 Nacos 控制台查看服务注册情况:
144+
145+
```
146+
http://localhost:8848/nacos
147+
用户名: nacos
148+
密码: nacos
149+
```
150+
151+
在服务列表中应该能看到 `providers:helloworld.Greeter::` 服务。
152+
153+
## 参考文档
154+
155+
- [Apache APISIX 文档](https://apisix.apache.org/zh/docs/apisix/getting-started)
156+
- [Dubbo-Go 官方文档](https://dubbogo.apache.org/)
157+
- [Nacos 官方文档](https://nacos.io/)

apisix/build.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# Build script for apisix example
3+
4+
set -e
5+
6+
echo "Building apisix server image..."
7+
8+
# Build from repository root
9+
cd "$(dirname "$0")/.."
10+
11+
# Build server image
12+
echo "Building server image..."
13+
docker build -f apisix/go-server/Dockerfile -t dubbo-go-apisix-server:latest .
14+
15+
echo "Build completed successfully!"
16+
echo ""
17+
echo "To run the example:"
18+
echo " 1. Create docker network: docker network create default_network"
19+
echo " 2. Start etcd: docker-compose -f apisix/deploy/etcd-compose/docker-compose.yml up -d"
20+
echo " 3. Start APISIX: docker-compose -f apisix/deploy/apisix-compose/docker-compose.yml up -d"
21+
echo " 4. Start Nacos: docker-compose -f apisix/deploy/nacos2.0.3-compose/docker-compose.yml up -d"
22+
echo " 5. Start the server: docker run -d --name dubbo-go-apisix-server --network default_network -e NACOS_ADDR=<nacos_ip>:8848 dubbo-go-apisix-server:latest"

compatibility/apisix/apisix-compose/apisix_conf/config.yaml renamed to apisix/deploy/apisix-compose/apisix_conf/config.yaml

File renamed without changes.
File renamed without changes.

compatibility/apisix/apisix-dashboard-compose/dashboard_conf/conf.yaml renamed to apisix/deploy/apisix-dashboard-compose/dashboard_conf/conf.yaml

File renamed without changes.

compatibility/apisix/apisix-dashboard-compose/docker-compose.yml renamed to apisix/deploy/apisix-dashboard-compose/docker-compose.yml

File renamed without changes.

compatibility/apisix/etcd-compose/docker-compose.yml renamed to apisix/deploy/etcd-compose/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3"
22
services:
33
etcd:
4-
image: bitnami/etcd:3.4.9
4+
image: quay.io/coreos/etcd:v3.4.9
55
user: root
66
restart: always
77
volumes:

0 commit comments

Comments
 (0)