@onlineapps/conn-infra-mq 1.1.46 → 1.1.47

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.46",
3
+ "version": "1.1.47",
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": {
@@ -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 queue - should already exist, skip checkQueue() to avoid channel closure
222
- console.log(`[RabbitMQClient] DEBUG: Business queue ${queue}, skipping checkQueue() in publish() - queue should already exist`);
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 - skip assertQueue() to avoid 406 channel closure
225
- // Infrastructure queues are created by monitoring consumer at startup
226
- // If queue doesn't exist, publish() will fail with a clear error
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