@onlineapps/conn-infra-mq 1.1.49 → 1.1.50

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.49",
3
+ "version": "1.1.50",
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": {
@@ -294,23 +294,55 @@ class RabbitMQClient extends EventEmitter {
294
294
  // Skip assertQueue for reply queues (they're already created with specific settings)
295
295
  // Reply queues start with 'rpc.reply.' and are created as non-durable
296
296
  if (!queue.startsWith('rpc.reply.')) {
297
- // Check if this is an infrastructure queue - services should NEVER create these
297
+ // CRITICAL: amqplib's channel.consume() may internally call assertQueue() without parameters
298
+ // This causes 406 errors if queue exists with different arguments
299
+ // Solution: Explicitly assertQueue() with correct parameters BEFORE consume()
298
300
  const isInfraQueue = queueConfig.isInfrastructureQueue(queue);
301
+ const isBusinessQueue = queueConfig.isBusinessQueue(queue);
302
+
303
+ let queueOptions = { durable };
299
304
 
300
305
  if (isInfraQueue) {
301
- // Infrastructure queue - should already exist, created by infrastructure initialization
302
- // CRITICAL: Do NOT use checkQueue() - it closes channel on 406 if queue exists with different args
303
- // Just proceed to consume() - if queue doesn't exist, consume() will fail with clear error
304
- // This avoids channel closure from checkQueue() on infrastructure queues
305
- console.log(`[RabbitMQClient] DEBUG: Infrastructure queue ${queue}, skipping checkQueue() - queue should already exist (created by infrastructure initialization)`);
306
- } else {
307
- // Business queue - should already be created by setupServiceQueues() BEFORE consume is called
308
- // CRITICAL: Do NOT use checkQueue() - it closes channel on 404!
309
- // If queue doesn't exist, that's a programming error (setupServiceQueues() should have created it)
310
- // Just proceed to consume - if queue doesn't exist, consume will fail with a clear error
311
- // This avoids channel closure from checkQueue() on non-existent queues
312
- console.log(`[RabbitMQClient] DEBUG: Business queue ${queue}, skipping checkQueue() - queue should already exist`);
306
+ // Infrastructure queue - use central config
307
+ try {
308
+ const infraConfig = queueConfig.getInfrastructureQueueConfig(queue);
309
+ queueOptions = {
310
+ durable: infraConfig.durable !== false,
311
+ arguments: { ...infraConfig.arguments }
312
+ };
313
+ console.log(`[RabbitMQClient] [CONSUMER] Asserting infrastructure queue ${queue} with config from queueConfig`);
314
+ } catch (configErr) {
315
+ console.warn(`[RabbitMQClient] [CONSUMER] Infrastructure queue config not found for ${queue}, using default:`, configErr.message);
316
+ }
317
+ } else if (isBusinessQueue) {
318
+ // Business queue - use central config
319
+ try {
320
+ const parsed = queueConfig.parseBusinessQueue(queue);
321
+ if (parsed) {
322
+ const businessConfig = queueConfig.getBusinessQueueConfig(parsed.queueType, parsed.serviceName);
323
+ queueOptions = {
324
+ durable: businessConfig.durable !== false,
325
+ arguments: { ...businessConfig.arguments }
326
+ };
327
+ console.log(`[RabbitMQClient] [CONSUMER] Asserting business queue ${queue} with config from queueConfig`);
328
+ }
329
+ } catch (configErr) {
330
+ console.warn(`[RabbitMQClient] [CONSUMER] Business queue config not found for ${queue}, using default:`, configErr.message);
331
+ }
313
332
  }
333
+
334
+ // CRITICAL: Assert queue with correct parameters BEFORE consume()
335
+ // This prevents amqplib from calling assertQueue() internally without parameters
336
+ const assertStartTime = Date.now();
337
+ console.log(`[RabbitMQClient] [CONSUMER] Asserting queue ${queue} before consume() at ${new Date().toISOString()}`);
338
+ console.log(`[RabbitMQClient] [CONSUMER] Queue options:`, JSON.stringify(queueOptions, null, 2));
339
+
340
+ // Use queueChannel for assertQueue to avoid RPC reply queue issues
341
+ const channelForAssert = this._queueChannel || this._channel;
342
+ await channelForAssert.assertQueue(queue, queueOptions);
343
+
344
+ const assertEndTime = Date.now();
345
+ console.log(`[RabbitMQClient] [CONSUMER] ✓ Queue ${queue} asserted (took ${assertEndTime - assertStartTime}ms)`);
314
346
  }
315
347
  // Set prefetch if provided
316
348
  if (typeof prefetch === 'number') {