@onlineapps/conn-infra-mq 1.1.4 → 1.1.6

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.4",
3
+ "version": "1.1.6",
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": {
@@ -163,19 +163,21 @@ class RabbitMQClient extends EventEmitter {
163
163
  // Use central config for infrastructure queues
164
164
  const queueOptions = this._getQueueOptions(queue, { durable });
165
165
 
166
- // Try to check if queue exists first (to avoid PRECONDITION-FAILED if it exists with different args)
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
+ // IMPORTANT: Don't try to re-assert after 406, as it will close the channel
167
169
  try {
168
- await this._channel.checkQueue(queue);
169
- // Queue exists - use it as-is (don't try to assert with different args)
170
- // This prevents 406 PRECONDITION-FAILED errors
171
- } catch (checkErr) {
172
- // Queue doesn't exist (404) - create it with our config
173
- if (checkErr.code === 404) {
174
- await this._channel.assertQueue(queue, queueOptions);
170
+ await this._channel.assertQueue(queue, queueOptions);
171
+ } catch (assertErr) {
172
+ // If queue exists with different arguments (406), use it as-is without re-asserting
173
+ // Re-asserting would close the channel, so we just log and proceed to consume
174
+ if (assertErr.code === 406) {
175
+ console.warn(`[RabbitMQClient] Queue ${queue} exists with different arguments, using as-is (skipping assert to avoid channel close):`, assertErr.message);
176
+ // Don't try to re-assert - just proceed to consume
177
+ // The queue exists, we just can't change its arguments
175
178
  } else {
176
- // Other error (e.g., 406) - queue exists with different args, use it as-is
177
- // Log warning but proceed to consume
178
- console.warn(`[RabbitMQClient] Queue ${queue} exists with different arguments, using as-is:`, checkErr.message);
179
+ // Other error (404 shouldn't happen with assertQueue, but handle it)
180
+ throw assertErr;
179
181
  }
180
182
  }
181
183
  }