@onlineapps/mq-client-core 1.0.68 → 1.0.70
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
package/src/BaseClient.js
CHANGED
|
@@ -188,21 +188,9 @@ class BaseClient {
|
|
|
188
188
|
|
|
189
189
|
try {
|
|
190
190
|
const consumeStartTime = Date.now();
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
try {
|
|
195
|
-
await messageHandler(msg);
|
|
196
|
-
if (consumeOptions.noAck === false) {
|
|
197
|
-
await this.ack(msg);
|
|
198
|
-
}
|
|
199
|
-
} catch (handlerErr) {
|
|
200
|
-
// On handler error, nack with requeue: true
|
|
201
|
-
await this.nack(msg, { requeue: true });
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
consumeOptions
|
|
205
|
-
);
|
|
191
|
+
// Delegate message lifecycle (ack/nack/requeue) to the transport layer.
|
|
192
|
+
// BaseClient only provides a broker-agnostic surface; transport decides how to handle handler errors.
|
|
193
|
+
await this._transport.consume(queue, async (msg) => messageHandler(msg), consumeOptions);
|
|
206
194
|
const consumeEndTime = Date.now();
|
|
207
195
|
console.log(`[BaseClient] [CONSUMER] ✓ consume() completed for queue: ${queue} (took ${consumeEndTime - consumeStartTime}ms)`);
|
|
208
196
|
} catch (err) {
|
|
@@ -419,6 +419,7 @@ class RabbitMQClient extends EventEmitter {
|
|
|
419
419
|
* @throws {Error} If connection or channel creation fails.
|
|
420
420
|
*/
|
|
421
421
|
async connect() {
|
|
422
|
+
let connectTimeoutTimer = null;
|
|
422
423
|
try {
|
|
423
424
|
const rawTarget = this._config.host || this._config.url;
|
|
424
425
|
const heartbeat = this._config.heartbeat ?? 30;
|
|
@@ -433,9 +434,11 @@ class RabbitMQClient extends EventEmitter {
|
|
|
433
434
|
: [{ ...rawTarget, heartbeat, clientProperties: { connection_name: connectionName } }];
|
|
434
435
|
|
|
435
436
|
const connectPromise = amqp.connect(...connectArgs);
|
|
436
|
-
let connectTimeoutTimer = null;
|
|
437
437
|
const timeoutPromise = new Promise((_, reject) => {
|
|
438
438
|
connectTimeoutTimer = setTimeout(() => reject(new Error('Connection timeout after 10 seconds')), 10000);
|
|
439
|
+
if (connectTimeoutTimer && typeof connectTimeoutTimer.unref === 'function') {
|
|
440
|
+
connectTimeoutTimer.unref();
|
|
441
|
+
}
|
|
439
442
|
});
|
|
440
443
|
console.log('[RabbitMQClient] Starting connection race...');
|
|
441
444
|
this._connection = await Promise.race([connectPromise, timeoutPromise]);
|
|
@@ -537,6 +540,11 @@ class RabbitMQClient extends EventEmitter {
|
|
|
537
540
|
this._connection = null;
|
|
538
541
|
}
|
|
539
542
|
throw err;
|
|
543
|
+
} finally {
|
|
544
|
+
if (connectTimeoutTimer) {
|
|
545
|
+
clearTimeout(connectTimeoutTimer);
|
|
546
|
+
connectTimeoutTimer = null;
|
|
547
|
+
}
|
|
540
548
|
}
|
|
541
549
|
}
|
|
542
550
|
|