@onlineapps/mq-client-core 1.0.3 → 1.0.5

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/mq-client-core",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Core MQ client library for RabbitMQ - shared by infrastructure services and connectors",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -122,22 +122,23 @@ class RabbitMQClient extends EventEmitter {
122
122
  // Ensure queue exists if publishing directly to queue and using default exchange
123
123
  if (!exchange) {
124
124
  // For infrastructure queues, they should already exist with specific arguments
125
- // Try to check if queue exists first, if not, create with default options
126
- // If it exists with different args (406), use it as-is
127
- const queueOptions = options.queueOptions || { durable: this._config.durable };
125
+ // Use checkQueue instead of assertQueue to avoid 406 PRECONDITION-FAILED
126
+ // If queue doesn't exist (404), try to create it with default options
128
127
  try {
129
- await this._channel.assertQueue(queue, queueOptions);
130
- } catch (assertErr) {
131
- // If queue exists with different arguments (406), use it as-is
132
- if (assertErr.code === 406) {
133
- console.warn(`[RabbitMQClient] Queue ${queue} exists with different arguments, using as-is:`, assertErr.message);
134
- // Don't try to re-assert - just proceed to publish
128
+ await this._channel.checkQueue(queue);
129
+ // Queue exists - proceed to publish
130
+ } catch (checkErr) {
131
+ // If queue doesn't exist (404), create it with default options
132
+ if (checkErr.code === 404) {
133
+ const queueOptions = options.queueOptions || { durable: this._config.durable };
134
+ await this._channel.assertQueue(queue, queueOptions);
135
135
  } else {
136
136
  // Other error - rethrow
137
- throw assertErr;
137
+ throw checkErr;
138
138
  }
139
139
  }
140
- this._channel.sendToQueue(queue, buffer, { persistent, headers, routingKey });
140
+ // Publish to queue (works even if queue has different arguments)
141
+ this._channel.sendToQueue(queue, buffer, { persistent, headers });
141
142
  } else {
142
143
  // If exchange is specified, assert exchange and publish to it
143
144
  await this._channel.assertExchange(exchange, 'direct', { durable: this._config.durable });