@onlineapps/conn-infra-mq 1.1.39 → 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 +27 -0
package/package.json
CHANGED
|
@@ -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
|
}
|