@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 +1 -1
- package/src/transports/rabbitmqClient.js +45 -13
package/package.json
CHANGED
|
@@ -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
|
-
//
|
|
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 -
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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') {
|