Skip to content

Commit f928462

Browse files
committed
fix: fix Dubbo protocol extension issue in test environment
- Set registry address to N/A to avoid ZooKeeper dependency - Change protocol from 'triple' to 'tri' to resolve extension loading error
1 parent e12665b commit f928462

File tree

5 files changed

+297
-20
lines changed

5 files changed

+297
-20
lines changed

modules/openapi-generator/src/main/resources/java-dubbo/application.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ dubbo:
66
application:
77
name: {{artifactId}}
88
logger: slf4j
9-
# 注册中心配置
109
registry:
1110
address: {{registryAddress}}
1211
# 协议配置
1312
protocol:
14-
name: triple
13+
name: tri
1514
port: -1 # auto-increment port
1615

17-
# 日志配置
1816
logging:
1917
level:
2018
root: INFO

modules/openapi-generator/src/main/resources/java-dubbo/pom.mustache

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@
4545
<artifactId>dubbo</artifactId>
4646
<version>${dubbo.version}</version>
4747
</dependency>
48-
<!-- 注册中心依赖 - 根据Dubbo版本和registry-address自动选择 -->
49-
<!-- 当前配置: {{registryAddress}} (Dubbo {{dubboVersion}}) -->
5048

5149
{{#isZookeeperRegistry}}
52-
<!-- Zookeeper 注册中心依赖 -->
50+
<!-- Zookeeper -->
5351
{{#isDubbo33Plus}}
54-
<!-- Dubbo 3.3+ 版本使用新的模块化依赖 -->
52+
<!-- Dubbo 3.3+ -->
5553
<dependency>
5654
<groupId>org.apache.dubbo</groupId>
5755
<artifactId>dubbo-registry-zookeeper</artifactId>
@@ -64,7 +62,7 @@
6462
</dependency>
6563
{{/isDubbo33Plus}}
6664
{{^isDubbo33Plus}}
67-
<!-- Dubbo 3.2 及之前版本使用聚合依赖 -->
65+
<!-- Dubbo 3.2 -->
6866
<dependency>
6967
<groupId>org.apache.dubbo</groupId>
7068
<artifactId>dubbo-dependencies-zookeeper</artifactId>
@@ -75,7 +73,7 @@
7573
{{/isZookeeperRegistry}}
7674

7775
{{#isNacosRegistry}}
78-
<!-- Nacos 注册中心依赖 -->
76+
<!-- Nacos -->
7977
<dependency>
8078
<groupId>org.apache.dubbo</groupId>
8179
<artifactId>dubbo-registry-nacos</artifactId>
@@ -89,9 +87,9 @@
8987
{{/isNacosRegistry}}
9088

9189
{{^isZookeeperRegistry}}{{^isNacosRegistry}}
92-
<!-- 默认使用Zookeeper注册中心依赖 -->
90+
<!-- 默认使用Zookeeper -->
9391
{{#isDubbo33Plus}}
94-
<!-- Dubbo 3.3+ 版本使用新的模块化依赖 -->
92+
<!-- Dubbo 3.3+ -->
9593
<dependency>
9694
<groupId>org.apache.dubbo</groupId>
9795
<artifactId>dubbo-registry-zookeeper</artifactId>
@@ -104,7 +102,7 @@
104102
</dependency>
105103
{{/isDubbo33Plus}}
106104
{{^isDubbo33Plus}}
107-
<!-- Dubbo 3.2 及之前版本使用聚合依赖 -->
105+
<!-- Dubbo 3.2 -->
108106
<dependency>
109107
<groupId>org.apache.dubbo</groupId>
110108
<artifactId>dubbo-dependencies-zookeeper</artifactId>
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
# OpenAPI Petstore
2+
3+
This is a sample server Petstore server. For this sample, you can use the api key &#x60;special-key&#x60; to test the authorization filters.
4+
5+
This is a microservice project based on Apache Dubbo, generated by [OpenAPI Generator](https://openapi-generator.tech).
6+
7+
- API version: 1.0.0
8+
- Package version:
9+
- Generator: org.openapitools.codegen.languages.DubboCodegen
10+
11+
## Technology Stack
12+
13+
- **Framework**: Apache Dubbo 3.2.18
14+
- **Java**: 8+
15+
- **Build Tool**: Maven 3.6+
16+
- **Registry**: zookeeper://127.0.0.1:2181
17+
- **Serialization**: Jackson JSON
18+
19+
## System Requirements
20+
21+
Building and running this project requires:
22+
1. Java 8+
23+
2. Maven 3.6+
24+
3. Registry Center (Nacos or Zookeeper)
25+
26+
## Quick Start
27+
28+
### 1. Clone and Build Project
29+
30+
```bash
31+
git clone <your-repo-url>
32+
cd openapi-dubbo-server-petstore
33+
mvn clean compile
34+
```
35+
36+
### 2. Configure Registry Center
37+
38+
#### Using Nacos (Recommended)
39+
```bash
40+
# Download and start Nacos
41+
wget https://github.com/alibaba/nacos/releases/download/2.2.4/nacos-server-2.2.4.tar.gz
42+
tar -xzf nacos-server-2.2.4.tar.gz
43+
cd nacos/bin
44+
# Linux/Mac
45+
./startup.sh -m standalone
46+
# Windows
47+
startup.cmd -m standalone
48+
```
49+
50+
#### Using Zookeeper (Alternative)
51+
```bash
52+
# Download and start Zookeeper
53+
wget https://downloads.apache.org/zookeeper/zookeeper-3.8.2/apache-zookeeper-3.8.2-bin.tar.gz
54+
tar -xzf apache-zookeeper-3.8.2-bin.tar.gz
55+
cd apache-zookeeper-3.8.2-bin
56+
cp conf/zoo_sample.cfg conf/zoo.cfg
57+
bin/zkServer.sh start
58+
```
59+
60+
### 3. Configure Application
61+
62+
Edit the `src/main/resources/application.yml` file:
63+
64+
```yaml
65+
# Dubbo Configuration
66+
dubbo:
67+
application:
68+
name: openapi-dubbo-server-petstore
69+
registry:
70+
# Using Nacos
71+
address: nacos://127.0.0.1:8848
72+
# Or using Zookeeper
73+
# address: zookeeper://127.0.0.1:2181
74+
protocol:
75+
name: dubbo
76+
port: 20880
77+
provider:
78+
timeout: 10000
79+
80+
```
81+
82+
### 4. Start Application
83+
84+
```bash
85+
# Build project
86+
mvn clean compile
87+
88+
# Run main class
89+
mvn exec:java -Dexec.mainClass=".Application"
90+
```
91+
92+
## Project Structure
93+
94+
```
95+
openapi-dubbo-server-petstore/
96+
├── src/main/java//
97+
│ └── Application.java # Main Application Class
98+
├── src/main/resources/
99+
│ └── application.yml # Application Configuration
100+
├── pom.xml # Maven Configuration
101+
└── README.md # Project Documentation
102+
```
103+
104+
## API Interfaces
105+
106+
107+
### Service Interfaces
108+
109+
110+
## Development Guide
111+
112+
### Implement Business Logic
113+
114+
1. Implement specific business logic in the generated `*DubboImpl.java` classes
115+
2. Inject necessary business service dependencies
116+
3. Handle exceptions and error scenarios
117+
118+
### Custom Configuration
119+
120+
1. **Timeout Configuration**: Adjust `dubbo.provider.timeout` in `application.yml`
121+
2. **Thread Pool Configuration**: Configure `dubbo.provider.threads` and other parameters
122+
3. **Serialization Configuration**: Choose appropriate serialization method
123+
124+
### Monitoring and Operations
125+
126+
1. **Health Checks**: Dubbo provides built-in health check endpoints
127+
2. **Metrics Monitoring**: Integrate with Prometheus or other monitoring systems
128+
3. **Log Management**: Configure appropriate log levels and output formats
129+
130+
## Testing
131+
132+
```bash
133+
# Run unit tests
134+
mvn test
135+
136+
# Run integration tests
137+
mvn integration-test
138+
```
139+
140+
## Deployment
141+
142+
### Development Environment
143+
```bash
144+
mvn spring-boot:run
145+
```
146+
147+
### Production Environment
148+
```bash
149+
# Build production package
150+
mvn clean package -Pprod
151+
152+
# Deploy using Docker
153+
docker build -t openapi-dubbo-server-petstore:1.0.0 .
154+
docker run -p 8080:8080 -p 20880:20880 openapi-dubbo-server-petstore:1.0.0
155+
```
156+
157+
## Generator Configuration Options
158+
159+
This project supports the following OpenAPI Generator configuration options:
160+
161+
### Basic Configuration
162+
- `title`: API service title name (Default: "OpenAPI Dubbo")
163+
- `basePackage`: Base package name (Default: "org.openapitools")
164+
- `configPackage`: Configuration class package name (Default: "org.openapitools.configuration")
165+
- `dubboVersion`: Dubbo version (Default: "3.2.0")
166+
167+
### Generation Control
168+
- `interfaceOnly`: Generate interfaces only, no implementation classes (Default: false)
169+
- `serviceInterface`: Generate service interfaces (Default: true)
170+
- `serviceImplementation`: Generate service implementations (Default: true)
171+
- `async`: Use asynchronous methods (Default: false)
172+
- `useTags`: Use tags to create class names (Default: true)
173+
- `useGenericResponse`: Use generic response wrapper (Default: false)
174+
175+
### Registry Configuration
176+
- `registry-address`: Registry address, supports full address format (Default: "zookeeper://127.0.0.1:2181")
177+
- Zookeeper example: `zookeeper://127.0.0.1:2181`
178+
- Nacos example: `nacos://127.0.0.1:8848`
179+
180+
#### 📋 Automatic Dependency Adaptation by Version
181+
The generator automatically selects the correct dependencies based on Dubbo version:
182+
183+
**Dubbo 3.2 and earlier versions**:
184+
- Zookeeper: `dubbo-dependencies-zookeeper` (Aggregation POM)
185+
- Nacos: `dubbo-registry-nacos` + `nacos-client:2.2.4`
186+
187+
**Dubbo 3.3+ versions**:
188+
- Zookeeper: `dubbo-registry-zookeeper` + `dubbo-remoting-zookeeper-curator5`
189+
- Nacos: `dubbo-registry-nacos` + `nacos-client:2.5.0`
190+
191+
### Date-Time Library Configuration
192+
- `dateLibrary`: Date-time library selection (Default: "java8")
193+
- `java8`: Java 8 native JSR310 (Recommended, for JDK 1.8+)
194+
- `java8-localdatetime`: Java 8 using LocalDateTime (For legacy applications only)
195+
- `joda`: Joda time library (For legacy applications only)
196+
- `legacy`: Traditional java.util.Date
197+
198+
### Usage Examples
199+
200+
#### 🔧 Dubbo 3.2 Version Example
201+
```bash
202+
# Using Zookeeper (3.2 version automatically uses dubbo-dependencies-zookeeper)
203+
java -jar openapi-generator-cli.jar generate \
204+
-i /Users/redoom/IdeaProjects/openapi.yaml \
205+
-g dubbo \
206+
-o /Users/redoom/IdeaProjects/openapi-test \
207+
--additional-properties=registry-address=zookeeper://127.0.0.1:2181 \
208+
--additional-properties=dubboVersion=3.2.0 \
209+
--additional-properties=dateLibrary=java8
210+
211+
# Using Nacos (3.2 version uses nacos-client:2.2.4)
212+
java -jar openapi-generator-cli.jar generate \
213+
-i /Users/redoom/IdeaProjects/openapi.yaml \
214+
-g dubbo \
215+
-o /Users/redoom/IdeaProjects/openapi-test \
216+
--additional-properties=registry-address=nacos://127.0.0.1:8848 \
217+
--additional-properties=dubboVersion=3.2.0 \
218+
--additional-properties=dateLibrary=java8
219+
```
220+
221+
#### 🚀 Dubbo 3.3+ Version Example
222+
```bash
223+
# Using Zookeeper (3.3+ version automatically uses new modular dependencies)
224+
java -jar openapi-generator-cli.jar generate \
225+
-i /Users/redoom/IdeaProjects/openapi.yaml \
226+
-g dubbo \
227+
-o /Users/redoom/IdeaProjects/openapi-test \
228+
--additional-properties=registry-address=zookeeper://127.0.0.1:2181 \
229+
--additional-properties=dubboVersion=3.3.0 \
230+
--additional-properties=dateLibrary=java8
231+
232+
# Using Nacos (3.3+ version uses nacos-client:2.5.0)
233+
java -jar openapi-generator-cli.jar generate \
234+
-i /Users/redoom/IdeaProjects/openapi.yaml \
235+
-g dubbo \
236+
-o /Users/redoom/IdeaProjects/openapi-test \
237+
--additional-properties=registry-address=nacos://127.0.0.1:8848 \
238+
--additional-properties=dubboVersion=3.3.0 \
239+
--additional-properties=dateLibrary=java8
240+
```
241+
242+
## Troubleshooting
243+
244+
### Common Issues
245+
246+
1. **Registry Connection Failed**
247+
- Check if the registry center is started
248+
- Verify network connection and port configuration
249+
250+
2. **Service Call Timeout**
251+
- Adjust `dubbo.provider.timeout` settings
252+
- Check network latency and service performance
253+
254+
3. **Serialization Exception**
255+
- Ensure all model classes implement `Serializable` interface
256+
- Check Jackson configuration
257+
258+
### Debug Logging
259+
260+
Enable debug mode to see detailed logs:
261+
262+
```yaml
263+
logging:
264+
level:
265+
org.apache.dubbo: DEBUG
266+
: DEBUG
267+
```
268+
269+
## License
270+
271+
This project is licensed under the [Apache License 2.0](LICENSE).
272+
273+
## Contributing
274+
275+
Issues and Pull Requests are welcome!
276+
277+
## Contact
278+
279+
280+
281+
---
282+
283+
> This project is automatically generated by OpenAPI Generator, based on Apache Dubbo microservice architecture.

samples/server/petstore/java-dubbo/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<modelVersion>4.0.0</modelVersion>
55

66
<groupId>org.openapitools</groupId>
7-
<artifactId>openapi-dubbo-server-petstore</artifactId>
7+
<artifactId>openapi-dubbo</artifactId>
88
<version>1.0.0</version>
99
<packaging>jar</packaging>
1010

11-
<name>OpenAPI Petstore</name>
12-
<description>This is a sample server Petstore server. For this sample, you can use the api key &#x60;special-key&#x60; to test the authorization filters.</description>
11+
<name>Financial Data API</name>
12+
<description>API for retrieving historical and real-time financial data for various products like A-Shares, US Stocks, Funds, and more.</description>
1313

1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
@@ -46,7 +46,7 @@
4646
<version>${dubbo.version}</version>
4747
</dependency>
4848
<!-- 注册中心依赖 - 根据Dubbo版本和registry-address自动选择 -->
49-
<!-- 当前配置: zookeeper://127.0.0.1:2181 (Dubbo 3.2.18) -->
49+
<!-- 当前配置: zookeeper://127.0.0.1:2181 (Dubbo 3.2.0) -->
5050

5151
<!-- Zookeeper 注册中心依赖 -->
5252
<!-- Dubbo 3.2 及之前版本使用聚合依赖 -->

samples/server/petstore/java-dubbo/src/main/resources/application.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ dubbo:
66
application:
77
name: openapi-dubbo-server-petstore
88
logger: slf4j
9-
# 注册中心配置
109
registry:
11-
address: zookeeper://127.0.0.1:2181
12-
# 协议配置
10+
address: N/A
1311
protocol:
14-
name: triple
12+
name: tri
1513
port: -1 # auto-increment port
1614

1715
# 日志配置

0 commit comments

Comments
 (0)