amqplib-init 1.2.0 → 1.2.1
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/module/ConfigResolver.js
CHANGED
|
@@ -15,13 +15,17 @@ class ConfigResolver {
|
|
|
15
15
|
finish: () => {},
|
|
16
16
|
amqpLink: '',
|
|
17
17
|
amqpAutoLink: '',
|
|
18
|
-
heartbeat:
|
|
19
|
-
timeout:
|
|
18
|
+
heartbeat: 60, // 增加心跳间隔到60秒,避免长时间处理时连接断开
|
|
19
|
+
timeout: 300000, // 增加连接超时到5分钟(300秒)
|
|
20
20
|
delay: 0,
|
|
21
21
|
autoReload: 0,
|
|
22
22
|
queryHook: () => {},
|
|
23
23
|
initHook: () => {},
|
|
24
|
-
durable: true
|
|
24
|
+
durable: true,
|
|
25
|
+
// 新增配置项 - 支持15分钟长任务
|
|
26
|
+
messageTimeout: 900000, // 消息处理超时15分钟(900秒)
|
|
27
|
+
reconnectDelay: 5000, // 重连延迟5秒
|
|
28
|
+
maxReconnectAttempts: 10 // 最大重连次数
|
|
25
29
|
};
|
|
26
30
|
}
|
|
27
31
|
|
|
@@ -28,7 +28,7 @@ class ConnectionManager {
|
|
|
28
28
|
* @returns {Promise<Object>} 返回频道对象
|
|
29
29
|
*/
|
|
30
30
|
async initialize() {
|
|
31
|
-
const { channelName, durable, prefetch, heartbeat, timeout, initHook } = this.config;
|
|
31
|
+
const { channelName, durable, prefetch, heartbeat, timeout, initHook, reconnectDelay } = this.config;
|
|
32
32
|
|
|
33
33
|
try {
|
|
34
34
|
// 建立连接
|
|
@@ -74,8 +74,9 @@ class ConnectionManager {
|
|
|
74
74
|
// 清理旧的channel状态
|
|
75
75
|
await this._cleanupOldChannel();
|
|
76
76
|
|
|
77
|
-
//
|
|
78
|
-
|
|
77
|
+
// 等待重连间隔,使用配置的延迟时间
|
|
78
|
+
const delaySeconds = (this.config.reconnectDelay || 5000) / 1000;
|
|
79
|
+
await happy.sleep(delaySeconds);
|
|
79
80
|
|
|
80
81
|
// 重新初始化连接
|
|
81
82
|
await this.initialize();
|
|
@@ -86,10 +87,11 @@ class ConnectionManager {
|
|
|
86
87
|
} catch (error) {
|
|
87
88
|
log.error('重连失败:', error.message);
|
|
88
89
|
// 如果重连失败,等待一段时间后重试
|
|
90
|
+
const retryDelay = this.config.reconnectDelay || 5000;
|
|
89
91
|
setTimeout(() => {
|
|
90
92
|
this.reconnectInProgress = false;
|
|
91
93
|
this.reconnect();
|
|
92
|
-
},
|
|
94
|
+
}, retryDelay);
|
|
93
95
|
throw error;
|
|
94
96
|
} finally {
|
|
95
97
|
this.reconnectInProgress = false;
|