@onlineapps/conn-infra-mq 1.1.46 → 1.1.48
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 +26 -27
package/package.json
CHANGED
|
@@ -211,23 +211,34 @@ class RabbitMQClient extends EventEmitter {
|
|
|
211
211
|
try {
|
|
212
212
|
// Ensure queue exists if publishing directly to queue and using default exchange
|
|
213
213
|
if (!exchange) {
|
|
214
|
-
// CRITICAL: For business queues, do NOT use checkQueue() - it closes channel on 404!
|
|
215
|
-
// Business queues should already be created by setupServiceQueues() BEFORE publish is called
|
|
216
|
-
// If queue doesn't exist, that's a programming error - just proceed to publish
|
|
217
|
-
// publish() will fail with a clear error if queue doesn't exist
|
|
218
214
|
const isBusinessQueue = queueConfig.isBusinessQueue(queue);
|
|
219
215
|
|
|
220
216
|
if (isBusinessQueue) {
|
|
221
|
-
// Business
|
|
222
|
-
|
|
217
|
+
// CRITICAL: Business queues MUST exist before publish
|
|
218
|
+
// sendToQueue() automatically creates queue with DEFAULT arguments if it doesn't exist
|
|
219
|
+
// This would create queue with wrong TTL, no DLQ, etc. - we MUST prevent this!
|
|
220
|
+
// Business queues must be created via setupServiceQueues() AFTER registration
|
|
221
|
+
// Use queueChannel (regular channel) to check existence without closing channel on 404
|
|
222
|
+
try {
|
|
223
|
+
await this._queueChannel.checkQueue(queue);
|
|
224
|
+
// Queue exists - safe to publish
|
|
225
|
+
console.log(`[RabbitMQClient] ✓ Business queue ${queue} exists, publishing...`);
|
|
226
|
+
} catch (checkErr) {
|
|
227
|
+
if (checkErr.code === 404) {
|
|
228
|
+
// Queue doesn't exist - this is a programming error
|
|
229
|
+
// Business queue should have been created by setupServiceQueues() after registration
|
|
230
|
+
throw new Error(`Business queue '${queue}' does not exist. Queue must be created via setupServiceQueues() AFTER successful registration. Cannot publish to non-existent business queue (would create it with wrong arguments).`);
|
|
231
|
+
}
|
|
232
|
+
// Other error - rethrow
|
|
233
|
+
throw checkErr;
|
|
234
|
+
}
|
|
223
235
|
} else {
|
|
224
|
-
// Infrastructure queue -
|
|
225
|
-
//
|
|
226
|
-
|
|
227
|
-
// This matches the pattern used for business queues - early creation, no runtime checks
|
|
228
|
-
console.log(`[RabbitMQClient] DEBUG: Infrastructure queue ${queue}, skipping assertQueue() - queue should already exist (created by monitoring consumer)`);
|
|
236
|
+
// Infrastructure queue - should already exist, created by infrastructure initialization
|
|
237
|
+
// If queue doesn't exist, that's an infrastructure problem
|
|
238
|
+
console.log(`[RabbitMQClient] DEBUG: Infrastructure queue ${queue}, assuming it exists (created by infrastructure initialization)`);
|
|
229
239
|
}
|
|
230
240
|
// Publish using ConfirmChannel (for publisher confirms)
|
|
241
|
+
// Queue exists, so sendToQueue() won't create it with wrong arguments
|
|
231
242
|
this._channel.sendToQueue(queue, buffer, { persistent, headers, routingKey });
|
|
232
243
|
} else {
|
|
233
244
|
// If exchange is specified, assert exchange and publish to it
|
|
@@ -271,22 +282,10 @@ class RabbitMQClient extends EventEmitter {
|
|
|
271
282
|
|
|
272
283
|
if (isInfraQueue) {
|
|
273
284
|
// Infrastructure queue - should already exist, created by infrastructure initialization
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
await this._queueChannel.checkQueue(queue);
|
|
279
|
-
console.log(`[RabbitMQClient] DEBUG: Infrastructure queue ${queue} exists`);
|
|
280
|
-
// Queue exists - proceed to consume
|
|
281
|
-
} catch (checkErr) {
|
|
282
|
-
console.error(`[RabbitMQClient] DEBUG: checkQueue failed for infrastructure queue ${queue}:`, checkErr.message);
|
|
283
|
-
if (checkErr.code === 404) {
|
|
284
|
-
// Queue doesn't exist - infrastructure problem
|
|
285
|
-
throw new Error(`Infrastructure queue '${queue}' not found. Queue should be created during infrastructure initialization.`);
|
|
286
|
-
}
|
|
287
|
-
// Other error - rethrow
|
|
288
|
-
throw checkErr;
|
|
289
|
-
}
|
|
285
|
+
// CRITICAL: Do NOT use checkQueue() - it closes channel on 406 if queue exists with different args
|
|
286
|
+
// Just proceed to consume() - if queue doesn't exist, consume() will fail with clear error
|
|
287
|
+
// This avoids channel closure from checkQueue() on infrastructure queues
|
|
288
|
+
console.log(`[RabbitMQClient] DEBUG: Infrastructure queue ${queue}, skipping checkQueue() - queue should already exist (created by infrastructure initialization)`);
|
|
290
289
|
} else {
|
|
291
290
|
// Business queue - should already be created by setupServiceQueues() BEFORE consume is called
|
|
292
291
|
// CRITICAL: Do NOT use checkQueue() - it closes channel on 404!
|