@platform-x/hep-message-broker-client 1.1.17 → 1.1.19
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.
|
@@ -491,7 +491,7 @@ class MessageBroker {
|
|
|
491
491
|
feed_type: (_m = (_l = msgData === null || msgData === void 0 ? void 0 : msgData.message) === null || _l === void 0 ? void 0 : _l.feed_type) !== null && _m !== void 0 ? _m : msgData === null || msgData === void 0 ? void 0 : msgData.feed_type,
|
|
492
492
|
};
|
|
493
493
|
try {
|
|
494
|
-
let success =
|
|
494
|
+
let success = {};
|
|
495
495
|
if (RABBITMQ.CONSUMER_RETRY_ERROR !== 'true' && RABBITMQ.CONSUMER_RETRY_ERROR !== true) {
|
|
496
496
|
if (typeof classInstance[consumerHandler] === 'function') {
|
|
497
497
|
logger_1.Logger.info('Consumer handler call for processing the request', 'consumeMessage');
|
|
@@ -501,32 +501,34 @@ class MessageBroker {
|
|
|
501
501
|
logger_1.Logger.error(`Method ${consumerHandler} not found on classInstance`, 'consumeMessage');
|
|
502
502
|
}
|
|
503
503
|
}
|
|
504
|
-
if (success) {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
else {
|
|
509
|
-
if (retryCount >= maxRetries) {
|
|
510
|
-
logger_1.Logger.error('Max retries reached. Sending message to Dead Letter Queue.', 'consumeMessage');
|
|
511
|
-
yield this.sendToDeadLetterQueue({ message: data, attempt: retryCount });
|
|
512
|
-
if (typeof classInstance[consumerErrorHandler] === 'function') {
|
|
513
|
-
classInstance[consumerErrorHandler](data);
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
logger_1.Logger.error(`Method ${consumerErrorHandler} not found on classInstance`, 'consumeMessage');
|
|
517
|
-
}
|
|
518
|
-
this.channel.nack(message, false, false);
|
|
504
|
+
if ((success === null || success === void 0 ? void 0 : success.isMatch) === true) {
|
|
505
|
+
if (success === null || success === void 0 ? void 0 : success.status) {
|
|
506
|
+
logger_1.Logger.info('Acknowledge the successful processing', 'consumeMessage');
|
|
507
|
+
this.channel.ack(message);
|
|
519
508
|
}
|
|
520
509
|
else {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
510
|
+
if (retryCount >= maxRetries) {
|
|
511
|
+
logger_1.Logger.error('Max retries reached. Sending message to Dead Letter Queue.', 'consumeMessage');
|
|
512
|
+
yield this.sendToDeadLetterQueue({ message: data, attempt: retryCount });
|
|
513
|
+
if (typeof classInstance[consumerErrorHandler] === 'function') {
|
|
514
|
+
classInstance[consumerErrorHandler](data);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
logger_1.Logger.error(`Method ${consumerErrorHandler} not found on classInstance`, 'consumeMessage');
|
|
518
|
+
}
|
|
519
|
+
this.channel.nack(message, false, false);
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
const nextAttempt = retryCount + 1;
|
|
523
|
+
if ((data === null || data === void 0 ? void 0 : data.retries) >= 0) {
|
|
524
|
+
data.retries = nextAttempt;
|
|
525
|
+
}
|
|
526
|
+
const delayIndex = nextAttempt - 1 < retryDelay.length ? nextAttempt - 1 : retryDelay.length - 1;
|
|
527
|
+
const delay = Number(retryDelay[delayIndex]);
|
|
528
|
+
logger_1.Logger.info(`Retrying in ${delay / 1000} seconds... (attempt ${nextAttempt} of ${maxRetries} ${data.feed_type})`, 'consumeMessage');
|
|
529
|
+
yield this.sendMessageToRetryQueue({ attempt: nextAttempt, data, retryDelayMs: delay, queueName });
|
|
530
|
+
this.channel.ack(message);
|
|
524
531
|
}
|
|
525
|
-
const delayIndex = nextAttempt - 1 < retryDelay.length ? nextAttempt - 1 : retryDelay.length - 1;
|
|
526
|
-
const delay = Number(retryDelay[delayIndex]);
|
|
527
|
-
logger_1.Logger.info(`Retrying in ${delay / 1000} seconds... (attempt ${nextAttempt} of ${maxRetries} ${data.feed_type})`, 'consumeMessage');
|
|
528
|
-
yield this.sendMessageToRetryQueue({ attempt: nextAttempt, data, retryDelayMs: delay, queueName });
|
|
529
|
-
this.channel.ack(message);
|
|
530
532
|
}
|
|
531
533
|
}
|
|
532
534
|
}
|
|
@@ -341,7 +341,7 @@ class MessageBrokerClient {
|
|
|
341
341
|
attempt = headers[retryCountHeader] || 0;
|
|
342
342
|
const data = { body: (_a = msgData === null || msgData === void 0 ? void 0 : msgData.result) === null || _a === void 0 ? void 0 : _a.data, queue_name: queueName, language: msgData === null || msgData === void 0 ? void 0 : msgData.language, correlationId: msgData === null || msgData === void 0 ? void 0 : msgData.correlationId, retries: msgData === null || msgData === void 0 ? void 0 : msgData.retries, item_id: msgData === null || msgData === void 0 ? void 0 : msgData.item_id, metadatakey: msgData === null || msgData === void 0 ? void 0 : msgData.metadatakey };
|
|
343
343
|
try {
|
|
344
|
-
let success =
|
|
344
|
+
let success = {};
|
|
345
345
|
if (RABBITMQ.CONSUMER_ERROR !== 'true' && RABBITMQ.CONSUMER_ERROR !== true) {
|
|
346
346
|
logger_1.Logger.info("Consumer handler call for process the request", 'consumeMessage');
|
|
347
347
|
// success = await this.consumerHandler({ queueName, message: msgData });
|
|
@@ -352,41 +352,50 @@ class MessageBrokerClient {
|
|
|
352
352
|
logger_1.Logger.info(`Method ${consumerHandler} not found in classInstance.`, 'consumerMessage');
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
classInstance[consumerErrorHandler]
|
|
355
|
+
if ((success === null || success === void 0 ? void 0 : success.isMatch) === true) {
|
|
356
|
+
if (!(success === null || success === void 0 ? void 0 : success.status)) {
|
|
357
|
+
const retryCount = message.properties.headers['x-retry-count'] || 0;
|
|
358
|
+
// while (retryCount < maxRetries) {
|
|
359
|
+
attempt = retryCount ? retryCount : attempt;
|
|
360
|
+
if (retryCount >= maxRetries) {
|
|
361
|
+
logger_1.Logger.error('Max retries reached. Failed to publish message.', 'consumeMessage');
|
|
362
|
+
// Optionally: Log or persist the failed message to a DB, file, or other storage for manual intervention
|
|
363
|
+
this.sendMessageToDeadLatter(attempt, data);
|
|
364
|
+
// this.consumerErrorHandler(data);
|
|
365
|
+
if (typeof classInstance[consumerErrorHandler] === 'function') {
|
|
366
|
+
classInstance[consumerErrorHandler](data); // Dynamically call the method
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
logger_1.Logger.info(`Method ${consumerErrorHandler} not found in classInstance.`, 'consumerMessage');
|
|
370
|
+
}
|
|
371
|
+
channel.nack(message, false, false); // Move message to DLQ after failure
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
attempt++;
|
|
375
|
+
if ((data === null || data === void 0 ? void 0 : data.retries) >= 0) {
|
|
376
|
+
data.retries = attempt;
|
|
377
|
+
}
|
|
378
|
+
// Wait before retrying (Exponential Backoff)
|
|
379
|
+
let retryDelay;
|
|
380
|
+
let count = retry_delay.length === attempt ? retry_delay[retry_delay.length - 1] : retry_delay[attempt - 1];
|
|
381
|
+
retryDelay = Number(count);
|
|
382
|
+
yield this.sendMessageToRetryQueue(attempt, data, retryDelay, queueName);
|
|
383
|
+
// retry method
|
|
384
|
+
if (typeof classInstance["consumerRetryHandler"] === 'function') {
|
|
385
|
+
classInstance["consumerRetryHandler"](data);
|
|
366
386
|
}
|
|
367
387
|
else {
|
|
368
|
-
logger_1.Logger.info(`Method
|
|
388
|
+
logger_1.Logger.info(`Method consumerRetryHandler not found in classInstance.`, 'consumerMessage');
|
|
369
389
|
}
|
|
370
|
-
|
|
371
|
-
|
|
390
|
+
logger_1.Logger.info(`Retrying in ${retryDelay / 1000} seconds...`, 'consumeMessage');
|
|
391
|
+
yield new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
372
392
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
data.retries = attempt;
|
|
393
|
+
else {
|
|
394
|
+
logger_1.Logger.info(`Acknowledge the successful processing`, 'consumeMessage');
|
|
376
395
|
}
|
|
377
|
-
//
|
|
378
|
-
|
|
379
|
-
let count = retry_delay.length === attempt ? retry_delay[retry_delay.length - 1] : retry_delay[attempt - 1];
|
|
380
|
-
retryDelay = Number(count);
|
|
381
|
-
yield this.sendMessageToRetryQueue(attempt, data, retryDelay, queueName);
|
|
382
|
-
logger_1.Logger.info(`Retrying in ${retryDelay / 1000} seconds...`, 'consumeMessage');
|
|
383
|
-
yield new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
logger_1.Logger.info(`Acknowledge the successful processing`, 'consumeMessage');
|
|
396
|
+
// Acknowledge the successful processing
|
|
397
|
+
channel.ack(message);
|
|
387
398
|
}
|
|
388
|
-
// Acknowledge the successful processing
|
|
389
|
-
channel.ack(message);
|
|
390
399
|
}
|
|
391
400
|
catch (error) {
|
|
392
401
|
let errorMessage = error.message;
|