proxy-pool-manager 1.0.0

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/README.md ADDED
@@ -0,0 +1,653 @@
1
+ # Proxy Manager SDK
2
+
3
+ 一个功能强大的代理管理器 SDK,提供代理管理、HTTP 请求封装、自动代理轮换和健康检查等功能。
4
+
5
+ ## ✨ 特性
6
+
7
+ - 🔄 **智能代理管理**:支持从 MongoDB 加载代理,自动验证和轮换
8
+ - 🌐 **HTTP 请求封装**:内置 HTTP 客户端,支持自动代理切换
9
+ - 📊 **代理健康检查**:自动检测代理可用性,支持自定义检测规则
10
+ - 🎯 **多种代理策略**:支持顺序、随机、故障转移三种策略
11
+ - 📦 **批量操作**:支持批量插入和管理代理
12
+ - 🔍 **日志系统**:基于 Winston 的完整日志记录
13
+ - ⚡ **异步队列**:高效的异步任务处理机制
14
+ - 🛡️ **类型安全**:完整的 TypeScript 类型定义
15
+
16
+ ## 📦 安装
17
+
18
+ ```bash
19
+ npm install proxy_manager
20
+ ```
21
+
22
+ ## 🚀 快速开始
23
+
24
+ ### 基本使用
25
+
26
+ ```typescript
27
+ import { createProxyRequest } from 'proxy_manager';
28
+
29
+ // 创建 SDK 实例
30
+ const sdk = await createProxyRequest({
31
+ mongoUri: 'mongodb://localhost:27017/proxy_db',
32
+ proxyStrategy: 'sequential',
33
+ logLevel: 'info',
34
+ timeout: 30,
35
+ proxyCheckOptions: {
36
+ mainUrl: 'http://example.com/check',
37
+ timeout: 10,
38
+ }
39
+ });
40
+
41
+ // 发送 GET 请求
42
+ const response = await sdk.get('https://api.example.com/data', {
43
+ params: { page: 1 }
44
+ });
45
+
46
+ console.log(response.data);
47
+ ```
48
+
49
+ ### 添加代理
50
+
51
+ ```typescript
52
+ // 添加单个代理
53
+ await sdk.addProxy('proxy.example.com:8080:username:password');
54
+
55
+ // 批量添加代理
56
+ const count = await sdk.bulkInsertProxies([
57
+ 'proxy1.example.com:8080:user1:pass1',
58
+ 'proxy2.example.com:8080:user2:pass2',
59
+ 'proxy3.example.com:8080:user3:pass3',
60
+ ]);
61
+
62
+ console.log(`成功添加 ${count} 个代理`);
63
+ ```
64
+
65
+ ### HTTP 请求方法
66
+
67
+ ```typescript
68
+ // GET 请求
69
+ const getResponse = await sdk.get('https://api.example.com/users', {
70
+ params: { page: 1, limit: 10 }
71
+ });
72
+
73
+ // POST 请求
74
+ const postResponse = await sdk.post('https://api.example.com/users', {
75
+ data: { name: 'John', email: 'john@example.com' },
76
+ headers: { 'Content-Type': 'application/json' }
77
+ });
78
+
79
+ // PUT 请求
80
+ const putResponse = await sdk.put('https://api.example.com/users/1', {
81
+ data: { name: 'Jane' }
82
+ });
83
+
84
+ // DELETE 请求
85
+ const deleteResponse = await sdk.delete('https://api.example.com/users/1');
86
+
87
+ // PATCH 请求
88
+ const patchResponse = await sdk.patch('https://api.example.com/users/1', {
89
+ data: { status: 'active' }
90
+ });
91
+
92
+ // 自定义请求
93
+ const customResponse = await sdk.request({
94
+ url: 'https://api.example.com/custom',
95
+ method: 'POST',
96
+ options: {
97
+ data: { custom: 'data' },
98
+ timeout: 60,
99
+ proxy: 'specific-proxy.com:8080' // 使用特定代理
100
+ }
101
+ });
102
+ ```
103
+
104
+ ## 📖 API 文档
105
+
106
+ ### ProxyRequestSDK
107
+
108
+ 主 SDK 类,提供统一的 API 接口。
109
+
110
+ #### 构造函数选项
111
+
112
+ ```typescript
113
+ interface SDKOptions {
114
+ mongoUri: string; // MongoDB 连接 URI(必需)
115
+ maxRetries?: number; // 最大重试次数,默认 3
116
+ timeout?: number; // 请求超时时间(秒),默认 30
117
+ proxyStrategy?: ProxyStrategy; // 代理策略,默认 'sequential'
118
+ logLevel?: LogLevel; // 日志级别,默认 'info'
119
+ instanceId?: string; // 实例 ID,用于多实例场景
120
+ proxyCheckOptions: { // 代理检查配置(必需)
121
+ mainUrl: string; // 代理检查主 URL(必需)
122
+ testUrls?: string[]; // 额外的测试 URL
123
+ timeout?: number; // 检查超时时间(秒)
124
+ successStatusCodes?: number[]; // 成功状态码列表
125
+ checkInterval?: number; // 检查间隔(毫秒)
126
+ maxConsecutiveFails?: number; // 最大连续失败次数
127
+ maxResponseTime?: number; // 最大响应时间(毫秒)
128
+ };
129
+ }
130
+ ```
131
+
132
+ #### 方法
133
+
134
+ ##### 请求方法
135
+
136
+ - `get<T>(url: string, params?: Record<string, string>, options?: RequestOptions): Promise<HttpResponse<T>>`
137
+ - `post<T>(url: string, options?: RequestOptions): Promise<HttpResponse<T>>`
138
+ - `put<T>(url: string, options?: RequestOptions): Promise<HttpResponse<T>>`
139
+ - `delete<T>(url: string, options?: RequestOptions): Promise<HttpResponse<T>>`
140
+ - `patch<T>(url: string, options?: RequestOptions): Promise<HttpResponse<T>>`
141
+ - `request<T>(config: RequestConfig): Promise<HttpResponse<T>>`
142
+
143
+ ##### 代理管理方法
144
+
145
+ - `addProxy(proxyUrl: string): Promise<ProxyItem | null>` - 添加代理
146
+ - `deleteProxy(proxyUrl: string): Promise<boolean>` - 删除代理
147
+ - `getAvailableProxies(): string[]` - 获取可用代理列表
148
+ - `getCurrentProxy(): string | null` - 获取当前使用的代理
149
+ - `rotateProxy(): Promise<string | null>` - 轮换到下一个代理
150
+ - `setProxyStrategy(strategy: ProxyStrategy): void` - 设置代理策略
151
+ - `checkProxy(proxy?: string): Promise<boolean>` - 检查代理可用性
152
+ - `triggerProxyCheck(): Promise<void>` - 触发代理检查
153
+ - `getProxyDetails(proxyUrl: string): ProxyItem | undefined` - 获取代理详情
154
+
155
+ ##### 批量操作
156
+
157
+ - `bulkInsertProxies(proxyUrls: string[]): Promise<number>` - 批量插入代理
158
+
159
+ ##### 统计信息
160
+
161
+ - `getProxyStats(): Promise<ProxyStats>` - 获取代理统计信息
162
+ - `getQueueStats(): QueueStats` - 获取队列统计信息
163
+
164
+ ##### 工具方法
165
+
166
+ - `waitForReady(): Promise<void>` - 等待初始化完成
167
+ - `setLogLevel(level: LogLevel): void` - 设置日志级别
168
+ - `getLogLevel(): LogLevel` - 获取当前日志级别
169
+ - `getInstanceId(): string` - 获取实例 ID
170
+ - `destroy(): Promise<void>` - 清理资源
171
+
172
+ ### 代理策略
173
+
174
+ 支持三种代理选择策略:
175
+
176
+ - **sequential**(顺序):按顺序使用代理列表中的代理
177
+ - **random**(随机):随机选择可用代理
178
+ - **failover**(故障转移):当前代理失败时自动切换到下一个
179
+
180
+ ### 日志级别
181
+
182
+ - `none` - 不记录日志
183
+ - `error` - 仅记录错误
184
+ - `warn` - 记录警告和错误
185
+ - `info` - 记录信息、警告和错误(默认)
186
+ - `debug` - 记录调试信息
187
+ - `verbose` - 记录所有详细信息
188
+
189
+ ## 🔧 高级用法
190
+
191
+ ### 多实例场景
192
+
193
+ ```typescript
194
+ import { initializeServices } from 'proxy_manager';
195
+
196
+ // 创建多个独立的 SDK 实例
197
+ const sdk1 = await initializeServices({
198
+ mongoUri: 'mongodb://localhost:27017/proxy_db',
199
+ instanceId: 'instance-1',
200
+ proxyCheckOptions: {
201
+ mainUrl: 'http://example.com/check'
202
+ }
203
+ });
204
+
205
+ const sdk2 = await initializeServices({
206
+ mongoUri: 'mongodb://localhost:27017/proxy_db',
207
+ instanceId: 'instance-2',
208
+ proxyCheckOptions: {
209
+ mainUrl: 'http://example.com/check'
210
+ }
211
+ });
212
+ ```
213
+
214
+ ### 自定义代理检查
215
+
216
+ ```typescript
217
+ const sdk = await createProxyRequest({
218
+ mongoUri: 'mongodb://localhost:27017/proxy_db',
219
+ proxyCheckOptions: {
220
+ mainUrl: 'https://httpbin.org/ip',
221
+ testUrls: [
222
+ 'https://api.ipify.org?format=json',
223
+ 'https://ipinfo.io/json'
224
+ ],
225
+ timeout: 15,
226
+ successStatusCodes: [200, 201],
227
+ checkInterval: 60000, // 每分钟检查一次
228
+ maxConsecutiveFails: 3, // 连续失败3次后标记为无效
229
+ maxResponseTime: 5000 // 最大响应时间5秒
230
+ }
231
+ });
232
+ ```
233
+
234
+ ### 请求级代理指定
235
+
236
+ ```typescript
237
+ // 为特定请求指定代理
238
+ const response = await sdk.get('https://api.example.com/data', {
239
+ proxy: 'specific-proxy.com:8080:user:pass'
240
+ });
241
+ ```
242
+
243
+ ### 代理统计信息
244
+
245
+ ```typescript
246
+ const stats = await sdk.getProxyStats();
247
+ console.log({
248
+ total: stats.total, // 总代理数
249
+ valid: stats.valid, // 有效代理数
250
+ invalid: stats.invalid, // 无效代理数
251
+ available: stats.available // 可用代理数
252
+ });
253
+
254
+ // 获取队列统计
255
+ const queueStats = sdk.getQueueStats();
256
+ console.log({
257
+ length: queueStats.length, // 队列长度
258
+ running: queueStats.running, // 运行中任务数
259
+ concurrency: queueStats.concurrency, // 并发数
260
+ idle: queueStats.idle // 是否空闲
261
+ });
262
+ ```
263
+
264
+ ### 批量插入代理
265
+
266
+ ```typescript
267
+ import { bulkInsertProxyUrls } from 'proxy_manager';
268
+
269
+ const count = await bulkInsertProxyUrls({
270
+ mongoUri: 'mongodb://localhost:27017/proxy_db',
271
+ proxyUrls: [
272
+ 'proxy1.com:8080:user1:pass1',
273
+ 'proxy2.com:8080:user2:pass2',
274
+ // ... 更多代理
275
+ ],
276
+ batchSize: 500, // 每批处理500个
277
+ concurrency: 4, // 并发4个批次
278
+ logLevel: 'info'
279
+ });
280
+
281
+ console.log(`成功插入 ${count} 个代理`);
282
+ ```
283
+
284
+ ## 📋 异步队列使用
285
+
286
+ `AsyncQueueSingleton` 是一个强大的异步任务队列管理器,支持并发控制、优先级任务、多实例等特性。
287
+
288
+ ### 队列快速开始
289
+
290
+ ```typescript
291
+ import { AsyncQueueSingleton } from 'proxy_manager';
292
+
293
+ // 创建队列实例
294
+ const queue = AsyncQueueSingleton.getInstance('my-queue', {
295
+ concurrency: 3, // 并发数:同时执行3个任务
296
+ autoStart: true, // 自动开始执行
297
+ logLevel: 'info',
298
+ onDrain: () => {
299
+ console.log('所有任务完成!');
300
+ },
301
+ onError: (error) => {
302
+ console.error('任务执行错误:', error);
303
+ },
304
+ onSuccess: (result) => {
305
+ console.log('任务成功:', result);
306
+ }
307
+ });
308
+
309
+ // 添加单个任务
310
+ const result = await queue.add({ id: 1, name: '任务1' });
311
+ console.log('任务结果:', result);
312
+
313
+ // 批量添加任务
314
+ const tasks = [
315
+ { id: 1, name: '任务1' },
316
+ { id: 2, name: '任务2' },
317
+ { id: 3, name: '任务3' }
318
+ ];
319
+ const results = await queue.addBatch(tasks);
320
+ console.log('批量任务结果:', results);
321
+ ```
322
+
323
+ ### 自定义任务处理器
324
+
325
+ ```typescript
326
+ // 创建队列并设置自定义处理器
327
+ const queue = AsyncQueueSingleton.getInstance('custom-queue', {
328
+ concurrency: 2,
329
+ logLevel: 'debug'
330
+ });
331
+
332
+ // 设置任务处理器
333
+ queue.setTaskHandler(async (task: any) => {
334
+ console.log(`处理任务: ${task.name}`);
335
+
336
+ // 模拟异步操作
337
+ await new Promise(resolve => setTimeout(resolve, task.duration));
338
+
339
+ // 返回处理结果
340
+ return {
341
+ taskId: task.id,
342
+ status: 'completed',
343
+ timestamp: new Date().toISOString()
344
+ };
345
+ });
346
+
347
+ // 添加任务
348
+ const result = await queue.add({ id: 1, name: '处理文件', duration: 1000 });
349
+ console.log(result);
350
+ ```
351
+
352
+ ### 队列控制
353
+
354
+ ```typescript
355
+ const queue = AsyncQueueSingleton.getInstance('control-queue', {
356
+ concurrency: 2,
357
+ autoStart: false // 手动控制启动
358
+ });
359
+
360
+ // 添加任务(队列已暂停,不会立即执行)
361
+ const promise = queue.add({ id: 1, name: '任务1' });
362
+
363
+ // 暂停队列
364
+ queue.pause();
365
+ console.log('队列已暂停');
366
+
367
+ // 恢复队列
368
+ queue.resume();
369
+ console.log('队列已恢复');
370
+
371
+ // 等待任务完成
372
+ const result = await promise;
373
+ ```
374
+
375
+ ### 优先级任务
376
+
377
+ ```typescript
378
+ const queue = AsyncQueueSingleton.getInstance('priority-queue', {
379
+ concurrency: 2
380
+ });
381
+
382
+ // 普通任务(priority = 0,默认)
383
+ await queue.add({ id: 1, name: '普通任务1' }, 0);
384
+
385
+ // 高优先级任务(priority > 0,会插入到队列前面)
386
+ await queue.add({ id: 2, name: '高优先级任务' }, 1);
387
+
388
+ // 最高优先级任务
389
+ await queue.add({ id: 3, name: '紧急任务' }, 2);
390
+ ```
391
+
392
+ ### 队列状态监控
393
+
394
+ ```typescript
395
+ const queue = AsyncQueueSingleton.getInstance('monitor-queue');
396
+
397
+ // 获取队列统计信息
398
+ const stats = queue.stats;
399
+ console.log({
400
+ length: stats.length, // 队列中等待的任务数
401
+ running: stats.running, // 正在执行的任务数
402
+ concurrency: stats.concurrency, // 并发数
403
+ idle: stats.idle // 是否空闲
404
+ });
405
+
406
+ // 获取队列长度
407
+ console.log('队列长度:', queue.length);
408
+
409
+ // 获取运行中任务数
410
+ console.log('运行中任务:', queue.running);
411
+
412
+ // 检查队列是否空闲
413
+ if (queue.idle) {
414
+ console.log('队列空闲,所有任务已完成');
415
+ }
416
+ ```
417
+
418
+ ### 多实例队列
419
+
420
+ ```typescript
421
+ // 创建不同类型的队列实例
422
+ const imageQueue = AsyncQueueSingleton.getInstance('image-processing', {
423
+ concurrency: 2,
424
+ taskHandler: async (task) => {
425
+ console.log(`处理图片: ${task.filename}`);
426
+ await new Promise(resolve => setTimeout(resolve, 2000));
427
+ return `图片处理完成: ${task.filename}`;
428
+ }
429
+ });
430
+
431
+ const dataQueue = AsyncQueueSingleton.getInstance('data-processing', {
432
+ concurrency: 5,
433
+ taskHandler: async (task) => {
434
+ console.log(`处理数据: ${task.id}`);
435
+ await new Promise(resolve => setTimeout(resolve, 500));
436
+ return `数据处理完成: ${task.id}`;
437
+ }
438
+ });
439
+
440
+ // 同时使用多个队列
441
+ const [imageResults, dataResults] = await Promise.all([
442
+ imageQueue.addBatch(imageTasks),
443
+ dataQueue.addBatch(dataTasks)
444
+ ]);
445
+
446
+ // 获取所有实例名称
447
+ const instanceNames = AsyncQueueSingleton.getInstanceNames();
448
+ console.log('所有队列实例:', instanceNames);
449
+
450
+ // 获取所有实例的统计信息
451
+ const allStats = AsyncQueueSingleton.getAllInstancesStats();
452
+ console.log('所有队列统计:', allStats);
453
+ ```
454
+
455
+ ### 动态调整并发数
456
+
457
+ ```typescript
458
+ const queue = AsyncQueueSingleton.getInstance('dynamic-queue', {
459
+ concurrency: 3
460
+ });
461
+
462
+ // 动态更新并发数
463
+ queue.updateConcurrency(5);
464
+ console.log('并发数已更新为:', queue.stats.concurrency);
465
+ ```
466
+
467
+ ### 泛型支持
468
+
469
+ ```typescript
470
+ // 使用泛型指定返回类型
471
+ interface ApiResponse {
472
+ endpoint: string;
473
+ status: string;
474
+ data: any;
475
+ }
476
+
477
+ const apiQueue = AsyncQueueSingleton.getInstance<ApiResponse>('api-queue', {
478
+ concurrency: 3
479
+ });
480
+
481
+ apiQueue.setTaskHandler(async (task: any): Promise<ApiResponse> => {
482
+ // 模拟API请求
483
+ await new Promise(resolve => setTimeout(resolve, 1000));
484
+
485
+ return {
486
+ endpoint: task.url,
487
+ status: 'success',
488
+ data: { result: 'ok' }
489
+ };
490
+ });
491
+
492
+ const response = await apiQueue.add({ url: '/api/users' });
493
+ // response 的类型是 ApiResponse
494
+ console.log(response.endpoint, response.status);
495
+ ```
496
+
497
+ ### 实际应用场景
498
+
499
+ #### 1. API 请求限流
500
+
501
+ ```typescript
502
+ const apiQueue = AsyncQueueSingleton.getInstance('api-rate-limit', {
503
+ concurrency: 5 // 限制同时最多5个API请求
504
+ });
505
+
506
+ apiQueue.setTaskHandler(async (apiCall: any) => {
507
+ const response = await fetch(apiCall.url);
508
+ return await response.json();
509
+ });
510
+
511
+ // 添加多个API请求,自动限流
512
+ const results = await apiQueue.addBatch([
513
+ { url: 'https://api.example.com/users' },
514
+ { url: 'https://api.example.com/orders' },
515
+ { url: 'https://api.example.com/products' }
516
+ ]);
517
+ ```
518
+
519
+ #### 2. 文件批量处理
520
+
521
+ ```typescript
522
+ const fileQueue = AsyncQueueSingleton.getInstance('file-processing', {
523
+ concurrency: 2,
524
+ onDrain: () => console.log('所有文件处理完成')
525
+ });
526
+
527
+ fileQueue.setTaskHandler(async (file: any) => {
528
+ // 处理文件
529
+ await processFile(file);
530
+ return `文件 ${file.name} 处理完成`;
531
+ });
532
+
533
+ const files = [
534
+ { name: 'document1.pdf', size: 1024 },
535
+ { name: 'image1.jpg', size: 2048 }
536
+ ];
537
+
538
+ const results = await fileQueue.addBatch(files);
539
+ ```
540
+
541
+ #### 3. 数据库操作队列
542
+
543
+ ```typescript
544
+ const dbQueue = AsyncQueueSingleton.getInstance('database-queue', {
545
+ concurrency: 1 // 串行执行,避免数据库锁冲突
546
+ });
547
+
548
+ dbQueue.setTaskHandler(async (operation: any) => {
549
+ // 执行数据库操作
550
+ await db.execute(operation);
551
+ return `操作完成: ${operation.type}`;
552
+ });
553
+
554
+ await dbQueue.add({ type: 'INSERT', table: 'users', data: {...} });
555
+ ```
556
+
557
+ ### 队列清理
558
+
559
+ ```typescript
560
+ // 销毁指定队列实例
561
+ AsyncQueueSingleton.destroyInstance('my-queue');
562
+
563
+ // 销毁所有队列实例
564
+ AsyncQueueSingleton.destroyAllInstances();
565
+ ```
566
+
567
+ ### AsyncQueue API 参考
568
+
569
+ #### 静态方法
570
+
571
+ - `getInstance<T>(name: string, options?: AsyncQueueOptions<T>): AsyncQueueSingleton<T>` - 获取或创建队列实例
572
+ - `getInstanceNames(): string[]` - 获取所有实例名称
573
+ - `getAllInstancesStats(): Record<string, QueueStats>` - 获取所有实例统计信息
574
+ - `hasInstance(name: string): boolean` - 检查实例是否存在
575
+ - `getExistingInstance<T>(name: string): AsyncQueueSingleton<T> | null` - 获取已存在的实例
576
+ - `destroyInstance(name: string): void` - 销毁指定实例
577
+ - `destroyAllInstances(): void` - 销毁所有实例
578
+
579
+ #### 实例方法
580
+
581
+ - `add(task: Task, priority?: number): Promise<T>` - 添加任务
582
+ - `addBatch(tasks: Task[], priority?: number): Promise<T[]>` - 批量添加任务
583
+ - `setTaskHandler(handler: (task: Task) => Promise<T>): void` - 设置任务处理器
584
+ - `updateConcurrency(newConcurrency: number): void` - 更新并发数
585
+ - `pause(): this` - 暂停队列
586
+ - `resume(): this` - 恢复队列
587
+ - `destroy(): void` - 销毁队列
588
+ - `setLogLevel(level: LogLevel): void` - 设置日志级别
589
+ - `getLogLevel(): LogLevel` - 获取日志级别
590
+ - `getName(): string` - 获取实例名称
591
+
592
+ #### 属性
593
+
594
+ - `length: number` - 队列长度
595
+ - `running: number` - 运行中任务数
596
+ - `idle: boolean` - 是否空闲
597
+ - `stats: QueueStats` - 队列统计信息
598
+
599
+ #### 配置选项
600
+
601
+ ```typescript
602
+ interface AsyncQueueOptions<T> {
603
+ concurrency?: number; // 并发数,默认 100
604
+ autoStart?: boolean; // 自动开始,默认 true
605
+ logLevel?: LogLevel; // 日志级别
606
+ onDrain?: () => void; // 队列排空回调
607
+ onError?: (error: Error) => void; // 错误回调
608
+ onSuccess?: (result: T) => void; // 成功回调
609
+ taskHandler?: (task: Task) => Promise<T>; // 任务处理器
610
+ }
611
+ ```
612
+
613
+ ## 🗄️ MongoDB 数据结构
614
+
615
+ 代理数据存储在 MongoDB 中,集合结构如下:
616
+
617
+ ```typescript
618
+ interface ProxyDocument {
619
+ url: string; // 代理 URL(格式:host:port:username:password)
620
+ totalRequests: number; // 总请求数
621
+ failCount: number; // 失败次数
622
+ avgResponseTime: number; // 平均响应时间(毫秒)
623
+ lastCheckTime: number; // 最后检查时间(时间戳)
624
+ consecutiveFails: number; // 连续失败次数
625
+ status: 'valid' | 'invalid'; // 状态
626
+ createdAt: Date; // 创建时间
627
+ updatedAt: Date; // 更新时间
628
+ }
629
+ ```
630
+
631
+ ## 📝 类型定义
632
+
633
+ 完整的 TypeScript 类型定义已包含在包中:
634
+
635
+ ```typescript
636
+ import type {
637
+ RequestOptions,
638
+ HttpResponse,
639
+ ProxyStrategy,
640
+ ProxyItem,
641
+ ProxyCheckOptions,
642
+ LogLevel
643
+ } from 'proxy_manager';
644
+ ```
645
+
646
+ ## ⚠️ 注意事项
647
+
648
+ 1. **MongoDB 连接**:确保 MongoDB 服务正在运行且连接 URI 正确
649
+ 2. **代理格式**:代理 URL 格式为 `host:port:username:password`
650
+ 3. **初始化等待**:SDK 初始化是异步的,使用 `waitForReady()` 确保初始化完成
651
+ 4. **资源清理**:使用完毕后调用 `destroy()` 方法清理资源
652
+ 5. **并发限制**:代理检查的并发数可通过 `maxConcurrentChecks` 配置
653
+