@onlineapps/conn-infra-mq 1.1.38 → 1.1.40
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 +1 -1
- package/src/layers/QueueManager.js +29 -2
package/package.json
CHANGED
|
@@ -266,7 +266,7 @@ class QueueManager {
|
|
|
266
266
|
console.error('[RabbitMQClient] Close reason:', channel._closeReason || 'Unknown');
|
|
267
267
|
});
|
|
268
268
|
|
|
269
|
-
transport.
|
|
269
|
+
transport._queueChannel = channel;
|
|
270
270
|
console.log(`[QueueManager] DEBUG: Channel recreated (was null) before ${queueInfo.name}`);
|
|
271
271
|
} else {
|
|
272
272
|
// Check if channel is closed - amqplib may not set closed property immediately
|
|
@@ -305,7 +305,7 @@ class QueueManager {
|
|
|
305
305
|
});
|
|
306
306
|
|
|
307
307
|
channel = newChannel;
|
|
308
|
-
transport.
|
|
308
|
+
transport._queueChannel = channel;
|
|
309
309
|
console.log(`[QueueManager] DEBUG: Channel recreated (check failed) before ${queueInfo.name}`);
|
|
310
310
|
channelUsable = true;
|
|
311
311
|
} catch (recreateErr) {
|
|
@@ -401,9 +401,36 @@ class QueueManager {
|
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
// If queue doesn't exist (404), create it using assertQueue
|
|
404
|
+
// CRITICAL: checkQueue() on 404 may close channel in amqplib, so we must check and recreate if needed
|
|
404
405
|
if (checkErr.code === 404) {
|
|
405
406
|
console.log(`[QueueManager] DEBUG: Queue ${queueName} doesn't exist (404), creating with assertQueue...`);
|
|
406
407
|
|
|
408
|
+
// CRITICAL: checkQueue() on 404 may close channel - check and recreate if needed
|
|
409
|
+
if (!channel || channel.closed) {
|
|
410
|
+
console.warn(`[QueueManager] DEBUG: Channel closed after checkQueue(404) for ${queueName}, recreating...`);
|
|
411
|
+
try {
|
|
412
|
+
const newChannel = await transport._connection.createChannel();
|
|
413
|
+
newChannel._createdAt = new Date().toISOString();
|
|
414
|
+
newChannel._closeReason = null;
|
|
415
|
+
newChannel._lastOperation = `Recreated after checkQueue(404) for ${queueName}`;
|
|
416
|
+
|
|
417
|
+
newChannel.on('error', (err) => {
|
|
418
|
+
console.error('[RabbitMQClient] Recreated queue channel error:', err.message);
|
|
419
|
+
newChannel._closeReason = `Error: ${err.message} (code: ${err.code})`;
|
|
420
|
+
});
|
|
421
|
+
newChannel.on('close', () => {
|
|
422
|
+
console.error('[RabbitMQClient] Recreated queue channel closed');
|
|
423
|
+
console.error('[RabbitMQClient] Close reason:', newChannel._closeReason || 'Unknown');
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
channel = newChannel;
|
|
427
|
+
transport._queueChannel = channel;
|
|
428
|
+
console.log(`[QueueManager] DEBUG: Channel recreated after checkQueue(404) for ${queueName}`);
|
|
429
|
+
} catch (recreateErr) {
|
|
430
|
+
throw new Error(`Channel closed after checkQueue(404) for ${queueName} and failed to recreate: ${recreateErr.message}`);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
407
434
|
if (channel && channel._lastOperation !== undefined) {
|
|
408
435
|
channel._lastOperation = `About to assertQueue ${queueName} (queue doesn't exist)`;
|
|
409
436
|
}
|