@dangao/bun-server 1.8.0 → 1.8.2

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.
Files changed (62) hide show
  1. package/docs/api.md +194 -81
  2. package/docs/extensions.md +53 -0
  3. package/docs/guide.md +243 -1
  4. package/docs/microservice-config-center.md +73 -74
  5. package/docs/microservice-nacos.md +89 -90
  6. package/docs/microservice-service-registry.md +85 -86
  7. package/docs/microservice.md +142 -137
  8. package/docs/request-lifecycle.md +45 -4
  9. package/docs/symbol-interface-pattern.md +106 -106
  10. package/docs/zh/api.md +458 -18
  11. package/docs/zh/extensions.md +53 -0
  12. package/docs/zh/guide.md +251 -4
  13. package/docs/zh/microservice-config-center.md +258 -0
  14. package/docs/zh/microservice-nacos.md +346 -0
  15. package/docs/zh/microservice-service-registry.md +306 -0
  16. package/docs/zh/microservice.md +680 -0
  17. package/docs/zh/request-lifecycle.md +43 -5
  18. package/package.json +1 -1
  19. package/tests/auth/auth-decorators.test.ts +241 -0
  20. package/tests/auth/oauth2-service.test.ts +318 -0
  21. package/tests/cache/cache-decorators-extended.test.ts +272 -0
  22. package/tests/cache/cache-interceptors.test.ts +534 -0
  23. package/tests/cache/cache-service-proxy.test.ts +246 -0
  24. package/tests/cache/memory-cache-store.test.ts +155 -0
  25. package/tests/cache/redis-cache-store.test.ts +199 -0
  26. package/tests/config/config-center-integration.test.ts +334 -0
  27. package/tests/config/config-module-extended.test.ts +165 -0
  28. package/tests/controller/param-binder.test.ts +333 -0
  29. package/tests/error/error-handler.test.ts +166 -57
  30. package/tests/error/i18n-extended.test.ts +105 -0
  31. package/tests/events/event-listener-scanner.test.ts +114 -0
  32. package/tests/events/event-module.test.ts +133 -302
  33. package/tests/extensions/logger-module.test.ts +158 -0
  34. package/tests/files/file-storage.test.ts +136 -0
  35. package/tests/interceptor/base-interceptor.test.ts +605 -0
  36. package/tests/interceptor/builtin/cache-interceptor.test.ts +233 -86
  37. package/tests/interceptor/builtin/log-interceptor.test.ts +469 -0
  38. package/tests/interceptor/builtin/permission-interceptor.test.ts +219 -120
  39. package/tests/interceptor/interceptor-chain.test.ts +241 -189
  40. package/tests/interceptor/interceptor-metadata.test.ts +221 -0
  41. package/tests/microservice/circuit-breaker.test.ts +221 -0
  42. package/tests/microservice/service-client-decorators.test.ts +86 -0
  43. package/tests/microservice/service-client-interceptors.test.ts +274 -0
  44. package/tests/microservice/service-registry-decorators.test.ts +147 -0
  45. package/tests/microservice/tracer.test.ts +213 -0
  46. package/tests/microservice/tracing-collectors.test.ts +168 -0
  47. package/tests/middleware/builtin/middleware-builtin-extended.test.ts +237 -0
  48. package/tests/middleware/builtin/rate-limit.test.ts +257 -0
  49. package/tests/middleware/middleware-decorators.test.ts +222 -0
  50. package/tests/middleware/middleware-pipeline.test.ts +160 -0
  51. package/tests/queue/queue-decorators.test.ts +139 -0
  52. package/tests/queue/queue-service.test.ts +191 -0
  53. package/tests/request/body-parser-extended.test.ts +291 -0
  54. package/tests/request/request-wrapper.test.ts +319 -0
  55. package/tests/router/router-decorators.test.ts +260 -0
  56. package/tests/router/router-extended.test.ts +298 -0
  57. package/tests/security/guards/reflector.test.ts +188 -0
  58. package/tests/security/security-filter.test.ts +182 -0
  59. package/tests/security/security-module-extended.test.ts +133 -0
  60. package/tests/session/memory-session-store.test.ts +172 -0
  61. package/tests/session/session-decorators.test.ts +163 -0
  62. package/tests/swagger/ui.test.ts +212 -0
@@ -1,26 +1,26 @@
1
- # 微服务架构支持
1
+ # Microservice Architecture Support
2
2
 
3
- Bun Server Framework 提供了完整的微服务架构支持,包括配置中心、服务注册与发现、服务调用、服务治理和可观测性等功能。
3
+ Bun Server Framework provides comprehensive microservice architecture support, including configuration center, service registration and discovery, service invocation, service governance, and observability features.
4
4
 
5
- ## 目录
5
+ ## Table of Contents
6
6
 
7
- - [快速开始](#快速开始)
8
- - [配置中心](#配置中心)
9
- - [服务注册与发现](#服务注册与发现)
10
- - [服务调用](#服务调用)
11
- - [服务治理](#服务治理)
12
- - [监控和追踪](#监控和追踪)
13
- - [最佳实践](#最佳实践)
7
+ - [Quick Start](#quick-start)
8
+ - [Configuration Center](#configuration-center)
9
+ - [Service Registration and Discovery](#service-registration-and-discovery)
10
+ - [Service Invocation](#service-invocation)
11
+ - [Service Governance](#service-governance)
12
+ - [Monitoring and Tracing](#monitoring-and-tracing)
13
+ - [Best Practices](#best-practices)
14
14
 
15
- ## 快速开始
15
+ ## Quick Start
16
16
 
17
- ### 安装依赖
17
+ ### Install Dependencies
18
18
 
19
19
  ```bash
20
20
  bun add @dangao/bun-server
21
21
  ```
22
22
 
23
- ### 基础示例
23
+ ### Basic Example
24
24
 
25
25
  ```typescript
26
26
  import { Application } from '@dangao/bun-server';
@@ -30,10 +30,10 @@ import {
30
30
  ServiceClient,
31
31
  } from '@dangao/bun-server';
32
32
 
33
- // 创建应用
33
+ // Create application
34
34
  const app = new Application();
35
35
 
36
- // 注册配置中心模块
36
+ // Register configuration center module
37
37
  app.registerModule(
38
38
  ConfigCenterModule.forRoot({
39
39
  provider: 'nacos',
@@ -48,7 +48,7 @@ app.registerModule(
48
48
  }),
49
49
  );
50
50
 
51
- // 注册服务注册中心模块
51
+ // Register service registry module
52
52
  app.registerModule(
53
53
  ServiceRegistryModule.forRoot({
54
54
  provider: 'nacos',
@@ -63,13 +63,13 @@ app.registerModule(
63
63
  }),
64
64
  );
65
65
 
66
- // 启动应用
66
+ // Start application
67
67
  await app.listen(3000);
68
68
  ```
69
69
 
70
- ## 配置中心
70
+ ## Configuration Center
71
71
 
72
- ### 基本使用
72
+ ### Basic Usage
73
73
 
74
74
  ```typescript
75
75
  import {
@@ -95,7 +95,7 @@ class MyService {
95
95
  }
96
96
  ```
97
97
 
98
- ### 使用装饰器
98
+ ### Using Decorators
99
99
 
100
100
  ```typescript
101
101
  import { ConfigCenterValue, Injectable } from '@dangao/bun-server';
@@ -104,32 +104,32 @@ import { ConfigCenterValue, Injectable } from '@dangao/bun-server';
104
104
  class MyService {
105
105
  @ConfigCenterValue('my-config', 'DEFAULT_GROUP', {
106
106
  defaultValue: 'default-value',
107
- watch: true, // 监听配置变更
107
+ watch: true, // Watch for configuration changes
108
108
  })
109
109
  public configValue: string = '';
110
110
 
111
111
  public getConfig() {
112
- return this.configValue; // 自动从配置中心获取
112
+ return this.configValue; // Automatically fetched from config center
113
113
  }
114
114
  }
115
115
  ```
116
116
 
117
- ### 配置热更新
117
+ ### Hot Configuration Update
118
118
 
119
- 配置中心支持配置热更新,当配置变更时会自动通知应用:
119
+ The configuration center supports hot configuration updates, automatically notifying the application when configurations change:
120
120
 
121
121
  ```typescript
122
122
  const configCenter = container.resolve<ConfigCenter>(CONFIG_CENTER_TOKEN);
123
123
 
124
124
  configCenter.watchConfig('my-config', 'DEFAULT_GROUP', (newConfig) => {
125
125
  console.log('Config updated:', newConfig.content);
126
- // 更新应用配置
126
+ // Update application configuration
127
127
  });
128
128
  ```
129
129
 
130
- ### ConfigModule 集成
130
+ ### ConfigModule Integration
131
131
 
132
- ConfigModule 支持与配置中心深度集成,配置变更会自动刷新:
132
+ ConfigModule supports deep integration with the configuration center, automatically refreshing when configurations change:
133
133
 
134
134
  ```typescript
135
135
  import { ConfigModule } from '@dangao/bun-server';
@@ -142,16 +142,16 @@ ConfigModule.forRoot({
142
142
  ['app.name', { dataId: 'app-name', groupName: 'DEFAULT_GROUP' }],
143
143
  ['app.port', { dataId: 'app-port', groupName: 'DEFAULT_GROUP' }],
144
144
  ]),
145
- configCenterPriority: true, // 配置中心配置优先级最高
145
+ configCenterPriority: true, // Config center has highest priority
146
146
  },
147
147
  });
148
148
  ```
149
149
 
150
- ## 服务注册与发现
150
+ ## Service Registration and Discovery
151
151
 
152
- ### 服务注册
152
+ ### Service Registration
153
153
 
154
- #### 使用装饰器自动注册
154
+ #### Automatic Registration with Decorator
155
155
 
156
156
  ```typescript
157
157
  import { ServiceRegistry, Controller, GET } from '@dangao/bun-server';
@@ -169,13 +169,13 @@ class UserController {
169
169
  }
170
170
  }
171
171
 
172
- // 应用启动时会自动注册服务
172
+ // Service will be automatically registered when application starts
173
173
  const app = new Application();
174
174
  app.registerController(UserController);
175
175
  await app.listen(3000);
176
176
  ```
177
177
 
178
- #### 手动注册
178
+ #### Manual Registration
179
179
 
180
180
  ```typescript
181
181
  import {
@@ -203,9 +203,9 @@ class MyService {
203
203
  }
204
204
  ```
205
205
 
206
- ### 服务发现
206
+ ### Service Discovery
207
207
 
208
- #### 使用装饰器自动发现
208
+ #### Automatic Discovery with Decorator
209
209
 
210
210
  ```typescript
211
211
  import { ServiceDiscovery, Injectable } from '@dangao/bun-server';
@@ -214,18 +214,18 @@ import type { ServiceInstance } from '@dangao/bun-server';
214
214
  @Injectable()
215
215
  class MyService {
216
216
  @ServiceDiscovery('user-service', {
217
- healthyOnly: true, // 只获取健康实例
217
+ healthyOnly: true, // Only get healthy instances
218
218
  })
219
219
  public instances: ServiceInstance[] = [];
220
220
 
221
221
  public async getAvailableInstances() {
222
- // instances 会自动更新
222
+ // instances will be automatically updated
223
223
  return this.instances;
224
224
  }
225
225
  }
226
226
  ```
227
227
 
228
- #### 手动发现
228
+ #### Manual Discovery
229
229
 
230
230
  ```typescript
231
231
  const instances = await serviceRegistry.getInstances('user-service', {
@@ -233,38 +233,38 @@ const instances = await serviceRegistry.getInstances('user-service', {
233
233
  namespaceId: 'public',
234
234
  });
235
235
 
236
- // 监听服务实例变更
236
+ // Watch for service instance changes
237
237
  serviceRegistry.watchInstances('user-service', (newInstances) => {
238
238
  console.log('Instances updated:', newInstances);
239
239
  });
240
240
  ```
241
241
 
242
- ### 健康检查集成
242
+ ### Health Check Integration
243
243
 
244
- 服务注册会自动集成健康检查模块,根据健康检查状态更新服务健康状态:
244
+ Service registration automatically integrates with the health check module, updating service health status based on health check results:
245
245
 
246
246
  ```typescript
247
247
  import { HealthModule } from '@dangao/bun-server';
248
248
 
249
- // 注册健康检查模块
249
+ // Register health check module
250
250
  HealthModule.forRoot({
251
251
  indicators: [
252
252
  {
253
253
  name: 'db',
254
254
  async check() {
255
- // 检查数据库连接
255
+ // Check database connection
256
256
  return { status: 'up' };
257
257
  },
258
258
  },
259
259
  ],
260
260
  });
261
261
 
262
- // 使用 @ServiceRegistry 装饰器的服务会自动根据健康检查状态更新
262
+ // Services using @ServiceRegistry decorator will automatically update based on health check status
263
263
  ```
264
264
 
265
- ## 服务调用
265
+ ## Service Invocation
266
266
 
267
- ### 基本使用
267
+ ### Basic Usage
268
268
 
269
269
  ```typescript
270
270
  import {
@@ -296,7 +296,7 @@ class MyService {
296
296
  }
297
297
  ```
298
298
 
299
- ### 使用装饰器注入
299
+ ### Using Decorator Injection
300
300
 
301
301
  ```typescript
302
302
  import { ServiceClient, Injectable } from '@dangao/bun-server';
@@ -317,12 +317,12 @@ class MyService {
317
317
  }
318
318
  ```
319
319
 
320
- ### 负载均衡
320
+ ### Load Balancing
321
321
 
322
- ServiceClient 支持多种负载均衡策略:
322
+ ServiceClient supports multiple load balancing strategies:
323
323
 
324
324
  ```typescript
325
- // 随机负载均衡
325
+ // Random load balancing
326
326
  await serviceClient.call({
327
327
  serviceName: 'user-service',
328
328
  method: 'GET',
@@ -330,7 +330,7 @@ await serviceClient.call({
330
330
  loadBalanceStrategy: 'random',
331
331
  });
332
332
 
333
- // 轮询负载均衡
333
+ // Round-robin load balancing
334
334
  await serviceClient.call({
335
335
  serviceName: 'user-service',
336
336
  method: 'GET',
@@ -338,7 +338,7 @@ await serviceClient.call({
338
338
  loadBalanceStrategy: 'roundRobin',
339
339
  });
340
340
 
341
- // 加权轮询
341
+ // Weighted round-robin
342
342
  await serviceClient.call({
343
343
  serviceName: 'user-service',
344
344
  method: 'GET',
@@ -346,7 +346,7 @@ await serviceClient.call({
346
346
  loadBalanceStrategy: 'weightedRoundRobin',
347
347
  });
348
348
 
349
- // 一致性哈希(适用于需要会话粘性的场景)
349
+ // Consistent hashing (for scenarios requiring session affinity)
350
350
  await serviceClient.call({
351
351
  serviceName: 'user-service',
352
352
  method: 'GET',
@@ -355,7 +355,7 @@ await serviceClient.call({
355
355
  consistentHashKey: 'user-id-123',
356
356
  });
357
357
 
358
- // 最少连接
358
+ // Least active
359
359
  await serviceClient.call({
360
360
  serviceName: 'user-service',
361
361
  method: 'GET',
@@ -364,9 +364,9 @@ await serviceClient.call({
364
364
  });
365
365
  ```
366
366
 
367
- ### 流式调用
367
+ ### Streaming Calls
368
368
 
369
- 支持 Server-Sent Events 等流式响应:
369
+ Supports streaming responses like Server-Sent Events:
370
370
 
371
371
  ```typescript
372
372
  const stream = await serviceClient.callStream({
@@ -375,7 +375,7 @@ const stream = await serviceClient.callStream({
375
375
  path: '/api/events',
376
376
  });
377
377
 
378
- // 读取流数据
378
+ // Read stream data
379
379
  const reader = stream.getReader();
380
380
  while (true) {
381
381
  const { done, value } = await reader.read();
@@ -384,9 +384,9 @@ while (true) {
384
384
  }
385
385
  ```
386
386
 
387
- ### 拦截器
387
+ ### Interceptors
388
388
 
389
- #### 请求拦截器
389
+ #### Request Interceptors
390
390
 
391
391
  ```typescript
392
392
  import {
@@ -397,7 +397,7 @@ import {
397
397
  serviceClient.addRequestInterceptor(new TraceIdRequestInterceptor());
398
398
  serviceClient.addRequestInterceptor(new RequestLogInterceptor());
399
399
 
400
- // 自定义请求拦截器
400
+ // Custom request interceptor
401
401
  serviceClient.addRequestInterceptor({
402
402
  async intercept(options) {
403
403
  options.headers = {
@@ -409,7 +409,7 @@ serviceClient.addRequestInterceptor({
409
409
  });
410
410
  ```
411
411
 
412
- #### 响应拦截器
412
+ #### Response Interceptors
413
413
 
414
414
  ```typescript
415
415
  import {
@@ -420,10 +420,10 @@ import {
420
420
  serviceClient.addResponseInterceptor(new ResponseLogInterceptor());
421
421
  serviceClient.addResponseInterceptor(new ErrorHandlerInterceptor());
422
422
 
423
- // 自定义响应拦截器
423
+ // Custom response interceptor
424
424
  serviceClient.addResponseInterceptor({
425
425
  async intercept(response) {
426
- // 转换响应数据
426
+ // Transform response data
427
427
  return {
428
428
  ...response,
429
429
  data: transformData(response.data),
@@ -432,24 +432,27 @@ serviceClient.addResponseInterceptor({
432
432
  });
433
433
  ```
434
434
 
435
- ## 服务治理
435
+ ## Service Governance
436
436
 
437
- ### 熔断器
437
+ ### Circuit Breaker
438
438
 
439
- #### 使用装饰器
439
+ #### Using Decorator
440
440
 
441
441
  ```typescript
442
442
  import { CircuitBreaker, Injectable } from '@dangao/bun-server';
443
443
 
444
444
  @Injectable()
445
445
  class MyService {
446
- @CircuitBreaker({
447
- failureThreshold: 0.5,
448
- timeWindow: 60000,
449
- minimumRequests: 10,
450
- }, 'fallbackMethod')
446
+ @CircuitBreaker(
447
+ {
448
+ failureThreshold: 0.5,
449
+ timeWindow: 60000,
450
+ minimumRequests: 10,
451
+ },
452
+ 'fallbackMethod',
453
+ )
451
454
  public async callExternalService() {
452
- // 自动应用熔断保护
455
+ // Automatically applies circuit breaker protection
453
456
  return await externalService.call();
454
457
  }
455
458
 
@@ -459,7 +462,7 @@ class MyService {
459
462
  }
460
463
  ```
461
464
 
462
- #### 手动使用
465
+ #### Manual Usage
463
466
 
464
467
  ```typescript
465
468
  import { CircuitBreaker } from '@dangao/bun-server';
@@ -474,15 +477,15 @@ const result = await circuitBreaker.execute(
474
477
  return await serviceClient.call(options);
475
478
  },
476
479
  async () => {
477
- // 降级处理
480
+ // Fallback handling
478
481
  return { fallback: true };
479
482
  },
480
483
  );
481
484
  ```
482
485
 
483
- ### 限流
486
+ ### Rate Limiting
484
487
 
485
- #### 内存限流
488
+ #### In-Memory Rate Limiting
486
489
 
487
490
  ```typescript
488
491
  import { RateLimiter } from '@dangao/bun-server';
@@ -498,12 +501,12 @@ if (!allowed) {
498
501
  }
499
502
  ```
500
503
 
501
- #### 分布式限流(Redis
504
+ #### Distributed Rate Limiting (Redis)
502
505
 
503
506
  ```typescript
504
507
  import { RedisRateLimiter } from '@dangao/bun-server';
505
508
 
506
- // 需要提供 Redis 客户端
509
+ // Redis client needs to be provided
507
510
  const redisClient = {
508
511
  get: async (key: string) => await redis.get(key),
509
512
  set: async (key: string, value: string, options?: any) => {
@@ -528,7 +531,7 @@ const rateLimiter = new RedisRateLimiter(
528
531
  const allowed = await rateLimiter.allow('service-key');
529
532
  ```
530
533
 
531
- ### 重试策略
534
+ ### Retry Strategy
532
535
 
533
536
  ```typescript
534
537
  import {
@@ -536,34 +539,37 @@ import {
536
539
  ExponentialBackoffRetryStrategy,
537
540
  } from '@dangao/bun-server';
538
541
 
539
- // 固定间隔重试
542
+ // Fixed interval retry
540
543
  const fixedRetry = new FixedIntervalRetryStrategy({
541
544
  maxRetries: 3,
542
545
  retryDelay: 1000,
543
546
  });
544
547
 
545
- // 指数退避重试
548
+ // Exponential backoff retry
546
549
  const exponentialRetry = new ExponentialBackoffRetryStrategy({
547
550
  maxRetries: 3,
548
551
  baseDelay: 1000,
549
552
  maxDelay: 30000,
550
553
  });
551
554
 
552
- // ServiceClient 中使用
555
+ // Use in ServiceClient
553
556
  serviceClient.setDefaultRetryStrategy({
554
557
  maxRetries: 3,
555
558
  retryDelay: 1000,
556
559
  exponentialBackoff: true,
557
560
  shouldRetry: (error) => {
558
- // 只对网络错误重试
559
- return error.message.includes('timeout') || error.message.includes('network');
561
+ // Only retry on network errors
562
+ return (
563
+ error.message.includes('timeout') ||
564
+ error.message.includes('network')
565
+ );
560
566
  },
561
567
  });
562
568
  ```
563
569
 
564
- ## 监控和追踪
570
+ ## Monitoring and Tracing
565
571
 
566
- ### 分布式追踪
572
+ ### Distributed Tracing
567
573
 
568
574
  ```typescript
569
575
  import {
@@ -579,40 +585,40 @@ const tracer = new Tracer({
579
585
 
580
586
  tracer.addCollector(new ConsoleTraceCollector());
581
587
 
582
- // ServiceClient 中使用
588
+ // Use in ServiceClient
583
589
  serviceClient.setTracer(tracer);
584
590
 
585
- // 手动创建 Span
591
+ // Manually create span
586
592
  const span = tracer.startSpan('my-operation', SpanKind.INTERNAL);
587
593
  tracer.setSpanTags(span.context.spanId, {
588
594
  'operation.name': 'process-data',
589
595
  'user.id': '123',
590
596
  });
591
- // ... 执行操作
597
+ // ... execute operation
592
598
  tracer.endSpan(span.context.spanId, SpanStatus.OK);
593
599
  ```
594
600
 
595
- ### 服务监控
601
+ ### Service Monitoring
596
602
 
597
603
  ```typescript
598
604
  import { ServiceMetricsCollector } from '@dangao/bun-server';
599
605
 
600
606
  const metricsCollector = new ServiceMetricsCollector({
601
607
  enabled: true,
602
- autoReportToMetrics: true, // 自动上报到 MetricsModule
608
+ autoReportToMetrics: true, // Automatically report to MetricsModule
603
609
  });
604
610
 
605
- // ServiceClient 中使用
611
+ // Use in ServiceClient
606
612
  serviceClient.setMetricsCollector(metricsCollector);
607
613
 
608
- // 查询指标
614
+ // Query metrics
609
615
  const allMetrics = metricsCollector.getAllMetrics();
610
616
  const healthStatus = metricsCollector.getAllHealthStatus();
611
617
  ```
612
618
 
613
- ### Prometheus 集成
619
+ ### Prometheus Integration
614
620
 
615
- 服务监控指标会自动上报到 MetricsModule,通过 `/metrics` 端点导出 Prometheus 格式:
621
+ Service monitoring metrics are automatically reported to MetricsModule and exported in Prometheus format via the `/metrics` endpoint:
616
622
 
617
623
  ```typescript
618
624
  import { MetricsModule } from '@dangao/bun-server';
@@ -621,60 +627,59 @@ MetricsModule.forRoot({
621
627
  enableHttpMetrics: true,
622
628
  });
623
629
 
624
- // 访问 http://localhost:3000/metrics 获取 Prometheus 格式指标
630
+ // Access http://localhost:3000/metrics to get Prometheus format metrics
625
631
  ```
626
632
 
627
- 导出的指标包括:
628
- - `service_calls_total` - 服务调用总数
629
- - `service_calls_success_total` - 成功调用数
630
- - `service_calls_failure_total` - 失败调用数
631
- - `service_call_latency_avg_ms` - 平均延迟
632
- - `service_call_latency_min_ms` - 最小延迟
633
- - `service_call_latency_max_ms` - 最大延迟
634
- - `service_call_error_rate` - 错误率
635
- - `service_instance_healthy` - 实例健康状态
636
- - `service_instance_consecutive_failures` - 连续失败次数
637
-
638
- ## 最佳实践
633
+ Exported metrics include:
634
+ - `service_calls_total` - Total service calls
635
+ - `service_calls_success_total` - Successful calls
636
+ - `service_calls_failure_total` - Failed calls
637
+ - `service_call_latency_avg_ms` - Average latency
638
+ - `service_call_latency_min_ms` - Minimum latency
639
+ - `service_call_latency_max_ms` - Maximum latency
640
+ - `service_call_error_rate` - Error rate
641
+ - `service_instance_healthy` - Instance health status
642
+ - `service_instance_consecutive_failures` - Consecutive failures
639
643
 
640
- ### 1. 配置管理
644
+ ## Best Practices
641
645
 
642
- - 使用配置中心管理动态配置
643
- - 为不同环境使用不同的命名空间
644
- - 启用配置监听以实现热更新
645
- - 设置合理的配置优先级
646
+ ### 1. Configuration Management
646
647
 
647
- ### 2. 服务注册
648
+ - Use configuration center to manage dynamic configurations
649
+ - Use different namespaces for different environments
650
+ - Enable configuration watching for hot updates
651
+ - Set reasonable configuration priorities
648
652
 
649
- - 使用 `@ServiceRegistry` 装饰器自动注册
650
- - 配置合理的服务元数据(版本、权重等)
651
- - 启用健康检查集成
652
- - 确保应用关闭时正确注销服务
653
+ ### 2. Service Registration
653
654
 
654
- ### 3. 服务调用
655
+ - Use `@ServiceRegistry` decorator for automatic registration
656
+ - Configure reasonable service metadata (version, weight, etc.)
657
+ - Enable health check integration
658
+ - Ensure services are properly deregistered when application shuts down
655
659
 
656
- - 选择合适的负载均衡策略
657
- - 配置合理的超时时间
658
- - 使用拦截器统一处理请求/响应
659
- - 启用追踪和监控
660
+ ### 3. Service Invocation
660
661
 
661
- ### 4. 服务治理
662
+ - Choose appropriate load balancing strategy
663
+ - Configure reasonable timeout values
664
+ - Use interceptors for unified request/response handling
665
+ - Enable tracing and monitoring
662
666
 
663
- - 为关键服务启用熔断器
664
- - 配置合理的限流策略
665
- - 实现降级处理逻辑
666
- - 使用重试策略处理临时故障
667
+ ### 4. Service Governance
667
668
 
668
- ### 5. 可观测性
669
+ - Enable circuit breaker for critical services
670
+ - Configure reasonable rate limiting strategies
671
+ - Implement fallback handling logic
672
+ - Use retry strategies for temporary failures
669
673
 
670
- - 启用分布式追踪
671
- - 配置合理的采样率
672
- - 集成 Prometheus 监控
673
- - 设置告警规则
674
+ ### 5. Observability
674
675
 
675
- ## 更多资源
676
+ - Enable distributed tracing
677
+ - Configure reasonable sampling rates
678
+ - Integrate Prometheus monitoring
679
+ - Set up alerting rules
676
680
 
677
- - [配置中心使用指南](./microservice-config-center.md)
678
- - [服务注册与发现使用指南](./microservice-service-registry.md)
679
- - [Nacos 集成文档](./microservice-nacos.md)
681
+ ## More Resources
680
682
 
683
+ - [Configuration Center Guide](./zh/microservice-config-center.md)
684
+ - [Service Registration and Discovery Guide](./zh/microservice-service-registry.md)
685
+ - [Nacos Integration Documentation](./zh/microservice-nacos.md)