@platform-x/hep-message-broker-client 1.1.22 → 1.1.24

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.
@@ -367,7 +367,7 @@ class MessageBroker {
367
367
  * @param request - The request object containing the queue name and the message payload
368
368
  * @returns true if the message was published successfully, false otherwise
369
369
  */
370
- publishMessage(request) {
370
+ publishMessage(classInstance, publishErrorHandler, publishRetryHandler, request) {
371
371
  return __awaiter(this, void 0, void 0, function* () {
372
372
  var _a, _b;
373
373
  logger_1.Logger.info('Reached to publishMessage', 'publishMessage');
@@ -375,7 +375,7 @@ class MessageBroker {
375
375
  const retryDelayConfig = ((_a = message === null || message === void 0 ? void 0 : message.message) === null || _a === void 0 ? void 0 : _a.feed_type) === constants_1.RABBITMQ_FEED_TYPE.OVR ? RABBITMQ.OVR_TTL : RABBITMQ.ETX_TTL;
376
376
  const retryDelay = retryDelayConfig.split('|').map(Number);
377
377
  let attempt = 0;
378
- while (attempt < maxRetries) {
378
+ while (attempt <= maxRetries) {
379
379
  try {
380
380
  yield this.checkConnectionAndChannel();
381
381
  const messageBuffer = Buffer.from(JSON.stringify(message));
@@ -392,15 +392,29 @@ class MessageBroker {
392
392
  catch (error) {
393
393
  attempt++;
394
394
  logger_1.Logger.error(`Attempt ${attempt} of ${maxRetries} failed in ${retryDelay[attempt - 1] / 1000}s...: ${error.message}`, 'publishMessage');
395
- if (attempt >= maxRetries) {
395
+ if (attempt > maxRetries) {
396
396
  logger_1.Logger.error('Max retries reached. Sending message to Dead Letter Queue...', 'publishMessage');
397
397
  yield this.sendToDeadLetterQueue({ message, attempt });
398
+ // Dead Letter Queue
399
+ if (typeof classInstance[publishErrorHandler] === 'function') {
400
+ classInstance[publishErrorHandler]({ message, retries: attempt });
401
+ }
402
+ else {
403
+ logger_1.Logger.error(`Method ${publishErrorHandler} not found on classInstance`, 'publishMessage');
404
+ }
398
405
  logger_1.Logger.error(`Failed to publish message to queue ${queueName} after ${maxRetries} attempts`, 'publishMessage');
399
406
  return false;
400
407
  }
401
408
  // Exponential backoff using TTL array
402
409
  const delay = (_b = retryDelay[attempt - 1]) !== null && _b !== void 0 ? _b : retryDelay[retryDelay.length - 1];
403
410
  logger_1.Logger.info(`Retrying in ${delay / 1000}s...`, 'publishMessage');
411
+ // Retry Queue 3 times
412
+ if (typeof classInstance[publishRetryHandler] === 'function') {
413
+ classInstance[publishRetryHandler]({ message, retries: attempt });
414
+ }
415
+ else {
416
+ logger_1.Logger.error(`Method ${publishRetryHandler} not found on classInstance`, 'publishMessage');
417
+ }
404
418
  yield new Promise(res => setTimeout(res, delay));
405
419
  }
406
420
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platform-x/hep-message-broker-client",
3
- "version": "1.1.22",
3
+ "version": "1.1.24",
4
4
  "description": "platform-x hep-message-broker service",
5
5
  "main": "./dist/src/index.js",
6
6
  "scripts": {