@onlineapps/mq-client-core 1.0.4 → 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 +1 -1
- package/src/transports/rabbitmqClient.js +12 -11
package/package.json
CHANGED
|
@@ -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
|
-
//
|
|
126
|
-
// If
|
|
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.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
|
137
|
+
throw checkErr;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
|
|
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 });
|