@onlineapps/conn-infra-mq 1.1.34 → 1.1.36

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.34",
3
+ "version": "1.1.36",
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": {
@@ -249,27 +249,37 @@ class QueueManager {
249
249
  for (const queueInfo of queueNames) {
250
250
  // CRITICAL: Check if channel is closed before each queue operation (may have been closed by previous 406)
251
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
252
253
  if (!channel) {
253
254
  console.warn(`[QueueManager] DEBUG: Channel is null before ${queueInfo.name}, recreating...`);
254
255
  channel = await transport._connection.createChannel();
255
256
  transport.queueChannel = channel;
256
257
  console.log(`[QueueManager] DEBUG: Channel recreated (was null) before ${queueInfo.name}`);
257
258
  } else {
258
- // Check if channel is closed - amqplib may set closed property or throw on use
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;
259
262
  try {
260
- // Try a no-op to see if channel is usable
261
- if (channel.closed === true) {
262
- console.warn(`[QueueManager] DEBUG: Channel is closed before ${queueInfo.name}, recreating...`);
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 {
263
272
  channel = await transport._connection.createChannel();
264
273
  transport.queueChannel = channel;
265
- console.log(`[QueueManager] DEBUG: Channel recreated (was closed) before ${queueInfo.name}`);
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}`);
266
278
  }
267
- } catch (checkErr) {
268
- // Channel may throw on access if closed - recreate it
269
- console.warn(`[QueueManager] DEBUG: Channel check failed before ${queueInfo.name}, recreating...`);
270
- channel = await transport._connection.createChannel();
271
- transport.queueChannel = channel;
272
- console.log(`[QueueManager] DEBUG: Channel recreated (check failed) before ${queueInfo.name}`);
279
+ }
280
+
281
+ if (!channelUsable) {
282
+ throw new Error(`Channel is not usable before ${queueInfo.name} and recreation failed`);
273
283
  }
274
284
  }
275
285