@onlineapps/conn-infra-mq 1.1.18 → 1.1.19

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.18",
3
+ "version": "1.1.19",
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": {
@@ -316,21 +316,43 @@ class QueueManager {
316
316
  queueOptions.arguments['x-expires'] = options.expires;
317
317
  }
318
318
 
319
- // Check if channel is open before assertQueue
319
+ // CRITICAL: amqplib's assertQueue() uses RPC pattern even on regular channels
320
+ // This causes channel closure if reply queue doesn't exist
321
+ // Solution: Create queue by sending an empty message to it using default exchange
322
+ // This avoids RPC reply queue issues with assertQueue()
323
+
324
+ // Check if channel is open
320
325
  if (!channel || channel.closed) {
321
326
  throw new Error('Channel is closed - cannot create temporary queue');
322
327
  }
323
328
 
329
+ // Use publish channel (ConfirmChannel) to send empty message, which creates the queue
330
+ const publishChannel = transport.channel;
331
+ if (!publishChannel || publishChannel.closed) {
332
+ throw new Error('Publish channel is closed - cannot create temporary queue');
333
+ }
334
+
324
335
  try {
325
- await channel.assertQueue(queueName, queueOptions);
336
+ // Send empty message to create queue (RabbitMQ creates queue automatically on first sendToQueue)
337
+ // This avoids RPC reply queue issues with assertQueue()
338
+ publishChannel.sendToQueue(queueName, Buffer.from(''), {
339
+ persistent: false
340
+ });
341
+
342
+ // Wait a moment for queue to be created
343
+ await new Promise(resolve => setTimeout(resolve, 100));
344
+
345
+ // Verify queue exists
346
+ await channel.checkQueue(queueName);
347
+
326
348
  this.managedQueues.add(queueName);
327
349
  return queueName;
328
- } catch (assertErr) {
329
- // If channel closed during assertQueue, throw descriptive error
330
- if (!channel || channel.closed) {
331
- throw new Error(`Channel closed during assertQueue for temporary queue ${queueName} - RPC reply queue issue detected`);
350
+ } catch (err) {
351
+ // If channel closed, throw descriptive error
352
+ if (!channel || channel.closed || !publishChannel || publishChannel.closed) {
353
+ throw new Error(`Channel closed during temporary queue creation for ${queueName} - RPC reply queue issue detected`);
332
354
  }
333
- throw assertErr;
355
+ throw err;
334
356
  }
335
357
  }
336
358