@onlineapps/conn-infra-mq 1.1.33 → 1.1.35

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/conn-infra-mq",
3
- "version": "1.1.33",
3
+ "version": "1.1.35",
4
4
  "description": "A promise-based, broker-agnostic client for sending and receiving messages via RabbitMQ",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -245,7 +245,44 @@ class QueueManager {
245
245
 
246
246
  // CRITICAL: Create ALL queues using assertQueue directly (no checkQueue first to avoid channel closure)
247
247
  // This ensures all queues are created atomically
248
+ // IMPORTANT: Channel may be closed on 406, so we need to check and recreate it before each queue
248
249
  for (const queueInfo of queueNames) {
250
+ // CRITICAL: Check if channel is closed before each queue operation (may have been closed by previous 406)
251
+ // Channel closes SYNCHRONOUSLY on 406, so we must check before each assertQueue
252
+ // amqplib's channel.closed may be undefined, so we test by trying a no-op operation
253
+ if (!channel) {
254
+ console.warn(`[QueueManager] DEBUG: Channel is null before ${queueInfo.name}, recreating...`);
255
+ channel = await transport._connection.createChannel();
256
+ transport.queueChannel = channel;
257
+ console.log(`[QueueManager] DEBUG: Channel recreated (was null) before ${queueInfo.name}`);
258
+ } else {
259
+ // Test if channel is usable by trying a no-op (checkQueue on a known queue)
260
+ // This will throw if channel is closed
261
+ let channelUsable = false;
262
+ try {
263
+ // Try to check a queue that definitely exists (workflow.init) - this tests channel usability
264
+ // If channel is closed, this will throw immediately
265
+ await channel.checkQueue('workflow.init');
266
+ channelUsable = true;
267
+ console.log(`[QueueManager] DEBUG: Channel is usable before ${queueInfo.name}`);
268
+ } catch (testErr) {
269
+ // Channel is closed or unusable - recreate it
270
+ console.warn(`[QueueManager] DEBUG: Channel test failed before ${queueInfo.name} (${testErr.message}), recreating...`);
271
+ try {
272
+ channel = await transport._connection.createChannel();
273
+ transport.queueChannel = channel;
274
+ console.log(`[QueueManager] DEBUG: Channel recreated (test failed) before ${queueInfo.name}`);
275
+ channelUsable = true;
276
+ } catch (recreateErr) {
277
+ throw new Error(`Failed to recreate channel before ${queueInfo.name}: ${recreateErr.message}`);
278
+ }
279
+ }
280
+
281
+ if (!channelUsable) {
282
+ throw new Error(`Channel is not usable before ${queueInfo.name} and recreation failed`);
283
+ }
284
+ }
285
+
249
286
  const queueName = queueInfo.name;
250
287
  let queueOptions;
251
288