@dangao/bun-server 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controller/controller.d.ts.map +1 -1
- package/dist/core/application.d.ts.map +1 -1
- package/dist/error/handler.d.ts.map +1 -1
- package/dist/index.js +98 -21
- package/dist/middleware/builtin/error-handler.d.ts.map +1 -1
- package/dist/middleware/builtin/logger.d.ts.map +1 -1
- package/dist/router/decorators.d.ts +10 -10
- package/dist/router/decorators.d.ts.map +1 -1
- package/dist/router/router.d.ts.map +1 -1
- package/docs/api.md +194 -81
- package/docs/extensions.md +53 -0
- package/docs/guide.md +243 -1
- package/docs/microservice-config-center.md +73 -74
- package/docs/microservice-nacos.md +89 -90
- package/docs/microservice-service-registry.md +85 -86
- package/docs/microservice.md +142 -137
- package/docs/request-lifecycle.md +45 -4
- package/docs/symbol-interface-pattern.md +106 -106
- package/docs/zh/api.md +458 -18
- package/docs/zh/extensions.md +53 -0
- package/docs/zh/guide.md +251 -4
- package/docs/zh/microservice-config-center.md +258 -0
- package/docs/zh/microservice-nacos.md +346 -0
- package/docs/zh/microservice-service-registry.md +306 -0
- package/docs/zh/microservice.md +680 -0
- package/docs/zh/request-lifecycle.md +43 -5
- package/package.json +1 -1
- package/src/controller/controller.ts +10 -2
- package/src/core/application.ts +11 -0
- package/src/error/handler.ts +17 -0
- package/src/middleware/builtin/error-handler.ts +10 -0
- package/src/middleware/builtin/logger.ts +17 -0
- package/src/router/decorators.ts +15 -15
- package/src/router/router.ts +18 -1
- package/tests/controller/path-combination.test.ts +135 -0
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Configuration Center Usage Guide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This document introduces how to use the configuration center feature in Bun Server Framework.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
- [
|
|
8
|
-
- [
|
|
9
|
-
- [
|
|
10
|
-
- [
|
|
11
|
-
- [ConfigModule
|
|
12
|
-
- [
|
|
13
|
-
- [
|
|
7
|
+
- [Overview](#overview)
|
|
8
|
+
- [Quick Start](#quick-start)
|
|
9
|
+
- [Basic Usage](#basic-usage)
|
|
10
|
+
- [Hot Configuration Update](#hot-configuration-update)
|
|
11
|
+
- [ConfigModule Integration](#configmodule-integration)
|
|
12
|
+
- [Decorator Usage](#decorator-usage)
|
|
13
|
+
- [Best Practices](#best-practices)
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Overview
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
The configuration center provides centralized configuration management capabilities, supporting:
|
|
18
18
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
19
|
+
- **Dynamic Configuration**: Fetch configurations from the configuration center with hot update support
|
|
20
|
+
- **Multi-Environment Support**: Manage configurations for different environments through namespaces and groups
|
|
21
|
+
- **Configuration Priority**: Config center > Environment variables > Default configuration
|
|
22
|
+
- **Configuration Watching**: Watch for configuration changes and automatically refresh application configuration
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## Quick Start
|
|
25
25
|
|
|
26
|
-
### 1.
|
|
26
|
+
### 1. Register Configuration Center Module
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
29
29
|
import { Application } from '@dangao/bun-server';
|
|
@@ -41,13 +41,13 @@ app.registerModule(
|
|
|
41
41
|
username: 'nacos',
|
|
42
42
|
password: 'nacos',
|
|
43
43
|
},
|
|
44
|
-
watchInterval: 3000, //
|
|
44
|
+
watchInterval: 3000, // Configuration polling interval (milliseconds)
|
|
45
45
|
},
|
|
46
46
|
}),
|
|
47
47
|
);
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
### 2.
|
|
50
|
+
### 2. Use Configuration Center
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
53
|
import {
|
|
@@ -72,15 +72,15 @@ class MyService {
|
|
|
72
72
|
}
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
##
|
|
75
|
+
## Basic Usage
|
|
76
76
|
|
|
77
|
-
###
|
|
77
|
+
### Get Configuration
|
|
78
78
|
|
|
79
79
|
```typescript
|
|
80
|
-
//
|
|
80
|
+
// Basic usage
|
|
81
81
|
const config = await configCenter.getConfig('my-config', 'DEFAULT_GROUP');
|
|
82
82
|
|
|
83
|
-
//
|
|
83
|
+
// Specify namespace
|
|
84
84
|
const config = await configCenter.getConfig(
|
|
85
85
|
'my-config',
|
|
86
86
|
'DEFAULT_GROUP',
|
|
@@ -88,20 +88,20 @@ const config = await configCenter.getConfig(
|
|
|
88
88
|
);
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
###
|
|
91
|
+
### Configuration Result
|
|
92
92
|
|
|
93
|
-
`getConfig`
|
|
93
|
+
`getConfig` returns a `ConfigResult` object:
|
|
94
94
|
|
|
95
95
|
```typescript
|
|
96
96
|
interface ConfigResult {
|
|
97
|
-
content: string; //
|
|
98
|
-
md5: string; //
|
|
99
|
-
lastModified: number; //
|
|
100
|
-
contentType: string; //
|
|
97
|
+
content: string; // Configuration content
|
|
98
|
+
md5: string; // Configuration MD5 (for change detection)
|
|
99
|
+
lastModified: number; // Last modified time (timestamp)
|
|
100
|
+
contentType: string; // Content type
|
|
101
101
|
}
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
###
|
|
104
|
+
### Watch Configuration Changes
|
|
105
105
|
|
|
106
106
|
```typescript
|
|
107
107
|
const unsubscribe = configCenter.watchConfig(
|
|
@@ -109,37 +109,37 @@ const unsubscribe = configCenter.watchConfig(
|
|
|
109
109
|
'DEFAULT_GROUP',
|
|
110
110
|
(newConfig) => {
|
|
111
111
|
console.log('Config updated:', newConfig.content);
|
|
112
|
-
//
|
|
112
|
+
// Update application configuration
|
|
113
113
|
updateAppConfig(JSON.parse(newConfig.content));
|
|
114
114
|
},
|
|
115
115
|
);
|
|
116
116
|
|
|
117
|
-
//
|
|
117
|
+
// Unsubscribe
|
|
118
118
|
unsubscribe();
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
##
|
|
121
|
+
## Hot Configuration Update
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
The configuration center supports hot configuration updates through a polling mechanism to detect configuration changes:
|
|
124
124
|
|
|
125
125
|
```typescript
|
|
126
126
|
ConfigCenterModule.forRoot({
|
|
127
127
|
provider: 'nacos',
|
|
128
128
|
nacos: {
|
|
129
|
-
watchInterval: 3000, //
|
|
129
|
+
watchInterval: 3000, // Check for configuration changes every 3 seconds
|
|
130
130
|
},
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
//
|
|
133
|
+
// Watch configuration changes
|
|
134
134
|
configCenter.watchConfig('my-config', 'DEFAULT_GROUP', (newConfig) => {
|
|
135
|
-
//
|
|
135
|
+
// Automatically called when configuration changes
|
|
136
136
|
console.log('Config hot updated:', newConfig.content);
|
|
137
137
|
});
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
## ConfigModule
|
|
140
|
+
## ConfigModule Integration
|
|
141
141
|
|
|
142
|
-
ConfigModule
|
|
142
|
+
ConfigModule supports deep integration with the configuration center, automatically refreshing ConfigService when configurations change:
|
|
143
143
|
|
|
144
144
|
```typescript
|
|
145
145
|
import { ConfigModule } from '@dangao/bun-server';
|
|
@@ -157,11 +157,11 @@ ConfigModule.forRoot({
|
|
|
157
157
|
['app.name', { dataId: 'app-name', groupName: 'DEFAULT_GROUP' }],
|
|
158
158
|
['app.port', { dataId: 'app-port', groupName: 'DEFAULT_GROUP' }],
|
|
159
159
|
]),
|
|
160
|
-
configCenterPriority: true, //
|
|
160
|
+
configCenterPriority: true, // Config center has highest priority
|
|
161
161
|
},
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
-
//
|
|
164
|
+
// Use ConfigService
|
|
165
165
|
import { CONFIG_SERVICE_TOKEN, ConfigService } from '@dangao/bun-server';
|
|
166
166
|
|
|
167
167
|
@Injectable()
|
|
@@ -171,22 +171,22 @@ class MyService {
|
|
|
171
171
|
) {}
|
|
172
172
|
|
|
173
173
|
public getAppName() {
|
|
174
|
-
//
|
|
174
|
+
// Automatically fetched from config center, auto-updated on changes
|
|
175
175
|
return this.config.get<string>('app.name');
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
```
|
|
179
179
|
|
|
180
|
-
###
|
|
180
|
+
### Configuration Priority
|
|
181
181
|
|
|
182
|
-
- `configCenterPriority: true
|
|
183
|
-
- `configCenterPriority: false
|
|
182
|
+
- `configCenterPriority: true` (default): Config center > Environment variables > Default configuration
|
|
183
|
+
- `configCenterPriority: false`: Default configuration > Environment variables > Config center
|
|
184
184
|
|
|
185
|
-
##
|
|
185
|
+
## Decorator Usage
|
|
186
186
|
|
|
187
187
|
### @ConfigCenterValue
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
Automatically inject configuration values:
|
|
190
190
|
|
|
191
191
|
```typescript
|
|
192
192
|
import { ConfigCenterValue, Injectable } from '@dangao/bun-server';
|
|
@@ -195,19 +195,19 @@ import { ConfigCenterValue, Injectable } from '@dangao/bun-server';
|
|
|
195
195
|
class MyService {
|
|
196
196
|
@ConfigCenterValue('app-name', 'DEFAULT_GROUP', {
|
|
197
197
|
defaultValue: 'MyApp',
|
|
198
|
-
watch: true, //
|
|
198
|
+
watch: true, // Watch for configuration changes
|
|
199
199
|
})
|
|
200
200
|
public appName: string = '';
|
|
201
201
|
|
|
202
202
|
public getAppName() {
|
|
203
|
-
return this.appName; //
|
|
203
|
+
return this.appName; // Automatically fetched from config center
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
```
|
|
207
207
|
|
|
208
208
|
### @NacosValue
|
|
209
209
|
|
|
210
|
-
Nacos
|
|
210
|
+
Nacos-specific configuration value injection (convenience alias):
|
|
211
211
|
|
|
212
212
|
```typescript
|
|
213
213
|
import { NacosValue, Injectable } from '@dangao/bun-server';
|
|
@@ -221,38 +221,37 @@ class MyService {
|
|
|
221
221
|
}
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
##
|
|
224
|
+
## Best Practices
|
|
225
225
|
|
|
226
|
-
### 1.
|
|
226
|
+
### 1. Configuration Organization
|
|
227
227
|
|
|
228
|
-
-
|
|
229
|
-
-
|
|
230
|
-
- **DataId
|
|
228
|
+
- **Namespace**: Used to distinguish different environments (dev, test, prod)
|
|
229
|
+
- **Group**: Used for logical grouping (DEFAULT_GROUP, DATABASE_GROUP, etc.)
|
|
230
|
+
- **DataId**: Unique identifier for configuration
|
|
231
231
|
|
|
232
|
-
### 2.
|
|
232
|
+
### 2. Configuration Format
|
|
233
233
|
|
|
234
|
-
-
|
|
235
|
-
-
|
|
234
|
+
- Recommended to use JSON format for storing configurations
|
|
235
|
+
- Supports plain text configurations (such as properties, yaml, etc.)
|
|
236
236
|
|
|
237
|
-
### 3.
|
|
237
|
+
### 3. Configuration Watching
|
|
238
238
|
|
|
239
|
-
-
|
|
240
|
-
-
|
|
241
|
-
-
|
|
239
|
+
- Enable watching for critical configurations (`watch: true`)
|
|
240
|
+
- Update application state promptly when configurations change
|
|
241
|
+
- Avoid frequent configuration changes
|
|
242
242
|
|
|
243
|
-
### 4.
|
|
243
|
+
### 4. Error Handling
|
|
244
244
|
|
|
245
|
-
-
|
|
246
|
-
-
|
|
247
|
-
-
|
|
245
|
+
- Use default values when configuration fetch fails
|
|
246
|
+
- Log configuration fetch errors
|
|
247
|
+
- Implement configuration fallback strategies
|
|
248
248
|
|
|
249
|
-
### 5.
|
|
249
|
+
### 5. Performance Optimization
|
|
250
250
|
|
|
251
|
-
-
|
|
252
|
-
-
|
|
253
|
-
-
|
|
251
|
+
- Set `watchInterval` reasonably (recommended 3-10 seconds)
|
|
252
|
+
- Use configuration caching to reduce API calls
|
|
253
|
+
- Batch fetch configurations (if supported)
|
|
254
254
|
|
|
255
|
-
##
|
|
256
|
-
|
|
257
|
-
完整示例请参考 `examples/microservice-app.ts`。
|
|
255
|
+
## Examples
|
|
258
256
|
|
|
257
|
+
For complete examples, please refer to `examples/microservice-app.ts`.
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
# Nacos
|
|
1
|
+
# Nacos Integration Documentation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This document introduces how to use Nacos as a configuration center and service registry in Bun Server Framework.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
- [
|
|
8
|
-
- [Nacos
|
|
9
|
-
- [
|
|
10
|
-
- [
|
|
11
|
-
- [
|
|
12
|
-
- [
|
|
7
|
+
- [Overview](#overview)
|
|
8
|
+
- [Nacos Installation](#nacos-installation)
|
|
9
|
+
- [Configuration Center Integration](#configuration-center-integration)
|
|
10
|
+
- [Service Registry Integration](#service-registry-integration)
|
|
11
|
+
- [Complete Example](#complete-example)
|
|
12
|
+
- [Common Issues](#common-issues)
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Overview
|
|
15
15
|
|
|
16
|
-
Bun Server Framework
|
|
16
|
+
Bun Server Framework provides Nacos 3.X support through the `@dangao/nacos-client` package, including:
|
|
17
17
|
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
- **Open API
|
|
18
|
+
- **Configuration Management**: Dynamic configuration fetching and watching
|
|
19
|
+
- **Service Registration**: Service instance registration, renewal, and deregistration
|
|
20
|
+
- **Service Discovery**: Service instance querying and watching
|
|
21
|
+
- **Open API**: Based on Nacos 3.X Open API implementation
|
|
22
22
|
|
|
23
|
-
## Nacos
|
|
23
|
+
## Nacos Installation
|
|
24
24
|
|
|
25
|
-
### Docker
|
|
25
|
+
### Docker Installation (Recommended)
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
docker run --name nacos -e MODE=standalone -p 8848:8848 nacos/nacos-server:v3.0.0
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
###
|
|
31
|
+
### Access Console
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
Visit http://localhost:8848/nacos, default username/password: `nacos/nacos`
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## Configuration Center Integration
|
|
36
36
|
|
|
37
|
-
### 1.
|
|
37
|
+
### 1. Register Configuration Center Module
|
|
38
38
|
|
|
39
39
|
```typescript
|
|
40
40
|
import { Application } from '@dangao/bun-server';
|
|
@@ -52,21 +52,21 @@ app.registerModule(
|
|
|
52
52
|
username: 'nacos',
|
|
53
53
|
password: 'nacos',
|
|
54
54
|
},
|
|
55
|
-
watchInterval: 3000, //
|
|
55
|
+
watchInterval: 3000, // Configuration polling interval (milliseconds)
|
|
56
56
|
},
|
|
57
57
|
}),
|
|
58
58
|
);
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
### 2.
|
|
61
|
+
### 2. Create Configuration in Nacos Console
|
|
62
62
|
|
|
63
|
-
1.
|
|
64
|
-
2.
|
|
65
|
-
3.
|
|
66
|
-
- **Data ID
|
|
67
|
-
- **Group
|
|
68
|
-
-
|
|
69
|
-
-
|
|
63
|
+
1. Log in to Nacos console
|
|
64
|
+
2. Go to "Configuration Management" -> "Configuration List"
|
|
65
|
+
3. Click "+" to create configuration:
|
|
66
|
+
- **Data ID**: `my-config`
|
|
67
|
+
- **Group**: `DEFAULT_GROUP`
|
|
68
|
+
- **Configuration Format**: `JSON` (or other formats)
|
|
69
|
+
- **Configuration Content**:
|
|
70
70
|
```json
|
|
71
71
|
{
|
|
72
72
|
"app": {
|
|
@@ -76,7 +76,7 @@ app.registerModule(
|
|
|
76
76
|
}
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
### 3.
|
|
79
|
+
### 3. Use Configuration
|
|
80
80
|
|
|
81
81
|
```typescript
|
|
82
82
|
import {
|
|
@@ -102,18 +102,18 @@ class MyService {
|
|
|
102
102
|
}
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
### 4.
|
|
105
|
+
### 4. Hot Configuration Update
|
|
106
106
|
|
|
107
107
|
```typescript
|
|
108
108
|
configCenter.watchConfig('my-config', 'DEFAULT_GROUP', (newConfig) => {
|
|
109
109
|
console.log('Config updated:', newConfig.content);
|
|
110
|
-
//
|
|
110
|
+
// Update application configuration
|
|
111
111
|
});
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
##
|
|
114
|
+
## Service Registry Integration
|
|
115
115
|
|
|
116
|
-
### 1.
|
|
116
|
+
### 1. Register Service Registry Module
|
|
117
117
|
|
|
118
118
|
```typescript
|
|
119
119
|
import { ServiceRegistryModule } from '@dangao/bun-server';
|
|
@@ -128,15 +128,15 @@ app.registerModule(
|
|
|
128
128
|
username: 'nacos',
|
|
129
129
|
password: 'nacos',
|
|
130
130
|
},
|
|
131
|
-
heartbeatInterval: 5000, //
|
|
131
|
+
heartbeatInterval: 5000, // Heartbeat interval (milliseconds)
|
|
132
132
|
},
|
|
133
133
|
}),
|
|
134
134
|
);
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
### 2.
|
|
137
|
+
### 2. Register Service
|
|
138
138
|
|
|
139
|
-
####
|
|
139
|
+
#### Using Decorator (Recommended)
|
|
140
140
|
|
|
141
141
|
```typescript
|
|
142
142
|
import { ServiceRegistry, Controller, GET } from '@dangao/bun-server';
|
|
@@ -156,10 +156,10 @@ class UserController {
|
|
|
156
156
|
|
|
157
157
|
app.registerController(UserController);
|
|
158
158
|
await app.listen(3000);
|
|
159
|
-
//
|
|
159
|
+
// Service will be automatically registered to Nacos
|
|
160
160
|
```
|
|
161
161
|
|
|
162
|
-
####
|
|
162
|
+
#### Manual Registration
|
|
163
163
|
|
|
164
164
|
```typescript
|
|
165
165
|
import {
|
|
@@ -186,7 +186,7 @@ class MyService {
|
|
|
186
186
|
}
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
-
### 3.
|
|
189
|
+
### 3. Service Discovery
|
|
190
190
|
|
|
191
191
|
```typescript
|
|
192
192
|
import {
|
|
@@ -199,13 +199,13 @@ const instances = await serviceRegistry.getInstances('user-service', {
|
|
|
199
199
|
namespaceId: 'public',
|
|
200
200
|
});
|
|
201
201
|
|
|
202
|
-
//
|
|
202
|
+
// Watch for service instance changes
|
|
203
203
|
serviceRegistry.watchInstances('user-service', (newInstances) => {
|
|
204
204
|
console.log('Instances updated:', newInstances);
|
|
205
205
|
});
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
-
##
|
|
208
|
+
## Complete Example
|
|
209
209
|
|
|
210
210
|
```typescript
|
|
211
211
|
import { Application, Controller, GET, Injectable, Inject } from '@dangao/bun-server';
|
|
@@ -219,7 +219,7 @@ import {
|
|
|
219
219
|
type ServiceRegistry,
|
|
220
220
|
} from '@dangao/bun-server';
|
|
221
221
|
|
|
222
|
-
//
|
|
222
|
+
// Register configuration center
|
|
223
223
|
ConfigCenterModule.forRoot({
|
|
224
224
|
provider: 'nacos',
|
|
225
225
|
nacos: {
|
|
@@ -232,7 +232,7 @@ ConfigCenterModule.forRoot({
|
|
|
232
232
|
},
|
|
233
233
|
});
|
|
234
234
|
|
|
235
|
-
//
|
|
235
|
+
// Register service registry
|
|
236
236
|
ServiceRegistryModule.forRoot({
|
|
237
237
|
provider: 'nacos',
|
|
238
238
|
nacos: {
|
|
@@ -245,7 +245,7 @@ ServiceRegistryModule.forRoot({
|
|
|
245
245
|
},
|
|
246
246
|
});
|
|
247
247
|
|
|
248
|
-
//
|
|
248
|
+
// Service class
|
|
249
249
|
@Injectable()
|
|
250
250
|
class UserService {
|
|
251
251
|
private readonly serviceClient: ServiceClient;
|
|
@@ -266,7 +266,7 @@ class UserService {
|
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
//
|
|
269
|
+
// Controller
|
|
270
270
|
@ServiceRegistry('user-service', { port: 3000 })
|
|
271
271
|
@Controller('/api/users')
|
|
272
272
|
class UserController {
|
|
@@ -278,69 +278,68 @@ class UserController {
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
//
|
|
281
|
+
// Start application
|
|
282
282
|
const app = new Application();
|
|
283
283
|
app.registerController(UserController);
|
|
284
284
|
await app.listen(3000);
|
|
285
285
|
```
|
|
286
286
|
|
|
287
|
-
##
|
|
287
|
+
## Common Issues
|
|
288
288
|
|
|
289
|
-
### 1.
|
|
289
|
+
### 1. Connection Failure
|
|
290
290
|
|
|
291
|
-
|
|
291
|
+
**Issue**: Unable to connect to Nacos server
|
|
292
292
|
|
|
293
|
-
|
|
294
|
-
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
297
|
-
-
|
|
293
|
+
**Solutions**:
|
|
294
|
+
- Check if Nacos server is running
|
|
295
|
+
- Check if `serverList` configuration is correct
|
|
296
|
+
- Check network connection and firewall settings
|
|
297
|
+
- Check if username and password are correct
|
|
298
298
|
|
|
299
|
-
### 2.
|
|
299
|
+
### 2. Configuration Fetch Failure
|
|
300
300
|
|
|
301
|
-
|
|
301
|
+
**Issue**: Unable to fetch configuration
|
|
302
302
|
|
|
303
|
-
|
|
304
|
-
-
|
|
305
|
-
-
|
|
306
|
-
-
|
|
307
|
-
-
|
|
303
|
+
**Solutions**:
|
|
304
|
+
- Check if configuration exists in Nacos console
|
|
305
|
+
- Check if Data ID and Group are correct
|
|
306
|
+
- Check if namespace is correct
|
|
307
|
+
- Check permission settings
|
|
308
308
|
|
|
309
|
-
### 3.
|
|
309
|
+
### 3. Service Registration Failure
|
|
310
310
|
|
|
311
|
-
|
|
311
|
+
**Issue**: Service cannot be registered to Nacos
|
|
312
312
|
|
|
313
|
-
|
|
314
|
-
-
|
|
315
|
-
-
|
|
316
|
-
-
|
|
317
|
-
-
|
|
313
|
+
**Solutions**:
|
|
314
|
+
- Check if service registry module is registered
|
|
315
|
+
- Check if service name, IP, and port are correct
|
|
316
|
+
- Check if Nacos server connection is normal
|
|
317
|
+
- Check application logs for detailed error information
|
|
318
318
|
|
|
319
|
-
### 4.
|
|
319
|
+
### 4. Service Discovery Returns Empty
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
**Issue**: Service discovery returns empty list
|
|
322
322
|
|
|
323
|
-
|
|
324
|
-
-
|
|
325
|
-
-
|
|
326
|
-
-
|
|
327
|
-
-
|
|
323
|
+
**Solutions**:
|
|
324
|
+
- Check if service is registered
|
|
325
|
+
- Check `healthyOnly` option (if set to true, only healthy instances are returned)
|
|
326
|
+
- Check if namespace and group are correct
|
|
327
|
+
- Check if service instances are healthy
|
|
328
328
|
|
|
329
|
-
### 5.
|
|
329
|
+
### 5. Hot Configuration Update Not Working
|
|
330
330
|
|
|
331
|
-
|
|
331
|
+
**Issue**: Application not updated after configuration changes
|
|
332
332
|
|
|
333
|
-
|
|
334
|
-
-
|
|
335
|
-
-
|
|
336
|
-
-
|
|
337
|
-
-
|
|
333
|
+
**Solutions**:
|
|
334
|
+
- Check if configuration watching is enabled (`watch: true`)
|
|
335
|
+
- Check if `watchInterval` setting is reasonable
|
|
336
|
+
- Check if configuration watch callback is correctly implemented
|
|
337
|
+
- Check logs to confirm if configuration changes are detected
|
|
338
338
|
|
|
339
|
-
##
|
|
339
|
+
## Reference Resources
|
|
340
340
|
|
|
341
|
-
- [Nacos
|
|
341
|
+
- [Nacos Official Documentation](https://nacos.io/docs/latest/)
|
|
342
342
|
- [Nacos 3.X Open API](https://nacos.io/docs/latest/manual/user/open-api/)
|
|
343
|
-
- [
|
|
344
|
-
- [
|
|
345
|
-
- [
|
|
346
|
-
|
|
343
|
+
- [Microservice Usage Guide](./microservice.md)
|
|
344
|
+
- [Configuration Center Usage Guide](./microservice-config-center.md)
|
|
345
|
+
- [Service Registration and Discovery Usage Guide](./microservice-service-registry.md)
|