@onlineapps/conn-infra-mq 1.1.12 → 1.1.14
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/package.json
CHANGED
|
@@ -82,18 +82,40 @@ class QueueManager {
|
|
|
82
82
|
|
|
83
83
|
// Use checkQueue first to avoid 406 PRECONDITION-FAILED closing the channel
|
|
84
84
|
// If queue doesn't exist (404), then assertQueue to create it
|
|
85
|
+
// IMPORTANT: Check if channel is still open before operations
|
|
86
|
+
if (!channel || channel.closed) {
|
|
87
|
+
throw new Error('Channel is closed - cannot ensure queue');
|
|
88
|
+
}
|
|
89
|
+
|
|
85
90
|
try {
|
|
86
|
-
await channel.checkQueue(queueName);
|
|
91
|
+
const queueInfo = await channel.checkQueue(queueName);
|
|
87
92
|
// Queue exists - return queue info
|
|
88
|
-
return
|
|
93
|
+
return queueInfo;
|
|
89
94
|
} catch (checkErr) {
|
|
95
|
+
// Check if channel is still open before assertQueue
|
|
96
|
+
if (!channel || channel.closed) {
|
|
97
|
+
throw new Error('Channel closed during checkQueue - cannot create queue');
|
|
98
|
+
}
|
|
99
|
+
|
|
90
100
|
// If queue doesn't exist (404), create it with provided options
|
|
91
101
|
if (checkErr.code === 404) {
|
|
92
|
-
|
|
102
|
+
try {
|
|
103
|
+
return await channel.assertQueue(queueName, queueOptions);
|
|
104
|
+
} catch (assertErr) {
|
|
105
|
+
// If channel closed during assertQueue, throw descriptive error
|
|
106
|
+
if (!channel || channel.closed) {
|
|
107
|
+
throw new Error(`Channel closed during assertQueue for ${queueName} - likely due to RPC reply queue issue`);
|
|
108
|
+
}
|
|
109
|
+
throw assertErr;
|
|
110
|
+
}
|
|
93
111
|
} else {
|
|
94
112
|
// Other error (including 406) - queue exists with different args
|
|
95
113
|
// Log warning and return queue info without asserting
|
|
96
114
|
console.warn(`[QueueManager] Queue ${queueName} exists with different arguments, using as-is:`, checkErr.message);
|
|
115
|
+
// Check channel again before checkQueue
|
|
116
|
+
if (!channel || channel.closed) {
|
|
117
|
+
throw new Error('Channel closed - cannot check queue');
|
|
118
|
+
}
|
|
97
119
|
return channel.checkQueue(queueName);
|
|
98
120
|
}
|
|
99
121
|
}
|
|
@@ -57,13 +57,25 @@ class RabbitMQClient extends EventEmitter {
|
|
|
57
57
|
this.emit('error', new Error('RabbitMQ connection closed unexpectedly'));
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
// Use ConfirmChannel to enable publisher confirms
|
|
60
|
+
// Use ConfirmChannel to enable publisher confirms for publish operations
|
|
61
|
+
// BUT: Create a separate regular channel for queue operations to avoid RPC reply queue issues
|
|
61
62
|
this._channel = await this._connection.createConfirmChannel();
|
|
62
63
|
this._channel.on('error', (err) => this.emit('error', err));
|
|
63
64
|
this._channel.on('close', () => {
|
|
64
65
|
// Emit a channel close error
|
|
65
66
|
this.emit('error', new Error('RabbitMQ channel closed unexpectedly'));
|
|
66
67
|
});
|
|
68
|
+
|
|
69
|
+
// Create a separate regular channel for queue operations (assertQueue, checkQueue)
|
|
70
|
+
// This avoids RPC reply queue issues with ConfirmChannel.assertQueue()
|
|
71
|
+
this._queueChannel = await this._connection.createChannel();
|
|
72
|
+
this._queueChannel.on('error', (err) => {
|
|
73
|
+
// Log but don't emit - queue channel errors are less critical
|
|
74
|
+
console.warn('[RabbitMQClient] Queue channel error:', err.message);
|
|
75
|
+
});
|
|
76
|
+
this._queueChannel.on('close', () => {
|
|
77
|
+
console.warn('[RabbitMQClient] Queue channel closed');
|
|
78
|
+
});
|
|
67
79
|
} catch (err) {
|
|
68
80
|
// Cleanup partially created resources
|
|
69
81
|
if (this._connection) {
|