@onlineapps/conn-infra-mq 1.1.5 → 1.1.7

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.5",
3
+ "version": "1.1.7",
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": {
@@ -160,30 +160,41 @@ class RabbitMQClient extends EventEmitter {
160
160
  // Skip assertQueue for reply queues (they're already created with specific settings)
161
161
  // Reply queues start with 'rpc.reply.' and are created as non-durable
162
162
  if (!queue.startsWith('rpc.reply.')) {
163
- // Use central config for infrastructure queues
164
- const queueOptions = this._getQueueOptions(queue, { durable });
163
+ // Check if this is an infrastructure queue - services should NEVER create these
164
+ const isInfraQueue = queueConfig.isInfrastructureQueue(queue);
165
165
 
166
- // Try to assert queue with our config
167
- // If it fails with 406 (PRECONDITION-FAILED), queue exists with different args - use it as-is
168
- try {
169
- await this._channel.assertQueue(queue, queueOptions);
170
- } catch (assertErr) {
171
- // If queue exists with different arguments (406), use it as-is
172
- if (assertErr.code === 406) {
173
- console.warn(`[RabbitMQClient] Queue ${queue} exists with different arguments, using as-is:`, assertErr.message);
174
- // Try to assert with minimal options (just durable) to verify queue exists
175
- try {
176
- await this._channel.assertQueue(queue, { durable: durable !== false });
177
- } catch (minErr) {
178
- // If even minimal assert fails, queue might not exist - log and proceed
179
- console.warn(`[RabbitMQClient] Could not assert queue ${queue} with minimal options:`, minErr.message);
166
+ if (isInfraQueue) {
167
+ // Infrastructure queue - should already exist, created by infrastructure initialization
168
+ // Only check if it exists, don't try to create or assert with arguments
169
+ try {
170
+ await this._channel.checkQueue(queue);
171
+ // Queue exists - proceed to consume
172
+ } catch (checkErr) {
173
+ if (checkErr.code === 404) {
174
+ // Queue doesn't exist - infrastructure problem
175
+ throw new Error(`Infrastructure queue '${queue}' not found. Queue should be created during infrastructure initialization.`);
180
176
  }
181
- } else if (assertErr.code === 404) {
182
- // Queue doesn't exist - this shouldn't happen with assertQueue, but handle it
183
- throw assertErr;
184
- } else {
185
177
  // Other error - rethrow
186
- throw assertErr;
178
+ throw checkErr;
179
+ }
180
+ } else {
181
+ // Business queue - may need to be created, but use unified config
182
+ const queueOptions = this._getQueueOptions(queue, { durable });
183
+
184
+ // Try to assert queue with our config
185
+ // If it fails with 406 (PRECONDITION-FAILED), queue exists with different args - use it as-is
186
+ // IMPORTANT: Don't try to re-assert after 406, as it will close the channel
187
+ try {
188
+ await this._channel.assertQueue(queue, queueOptions);
189
+ } catch (assertErr) {
190
+ // If queue exists with different arguments (406), use it as-is without re-asserting
191
+ if (assertErr.code === 406) {
192
+ console.warn(`[RabbitMQClient] Queue ${queue} exists with different arguments, using as-is (skipping assert to avoid channel close):`, assertErr.message);
193
+ // Don't try to re-assert - just proceed to consume
194
+ } else {
195
+ // Other error - rethrow
196
+ throw assertErr;
197
+ }
187
198
  }
188
199
  }
189
200
  }