|
| 1 | +# OpenAPI Petstore |
| 2 | + |
| 3 | +This is a sample server Petstore server. For this sample, you can use the api key `special-key` 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. |
0 commit comments