@solidxai/core 0.1.6-beta.23 → 0.1.6-beta.25

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.
Files changed (82) hide show
  1. package/dist/entities/mq-message-queue.entity.d.ts.map +1 -1
  2. package/dist/entities/mq-message-queue.entity.js.map +1 -1
  3. package/dist/helpers/bootstrap.helper.js +1 -1
  4. package/dist/helpers/bootstrap.helper.js.map +1 -1
  5. package/dist/helpers/cors.helper.d.ts.map +1 -1
  6. package/dist/helpers/cors.helper.js +4 -1
  7. package/dist/helpers/cors.helper.js.map +1 -1
  8. package/dist/interfaces.d.ts +1 -0
  9. package/dist/interfaces.d.ts.map +1 -1
  10. package/dist/interfaces.js.map +1 -1
  11. package/dist/jobs/chatter-queue-options.js +1 -1
  12. package/dist/jobs/chatter-queue-options.js.map +1 -1
  13. package/dist/jobs/chatter-queue-publisher.service.d.ts +9 -9
  14. package/dist/jobs/chatter-queue-publisher.service.d.ts.map +1 -1
  15. package/dist/jobs/chatter-queue-publisher.service.js +5 -5
  16. package/dist/jobs/chatter-queue-publisher.service.js.map +1 -1
  17. package/dist/jobs/chatter-queue-subscriber.service.d.ts +4 -4
  18. package/dist/jobs/chatter-queue-subscriber.service.d.ts.map +1 -1
  19. package/dist/jobs/chatter-queue-subscriber.service.js +11 -11
  20. package/dist/jobs/chatter-queue-subscriber.service.js.map +1 -1
  21. package/dist/jobs/computed-field-evaluation-queue-options.d.ts +1 -0
  22. package/dist/jobs/computed-field-evaluation-queue-options.d.ts.map +1 -1
  23. package/dist/jobs/computed-field-evaluation-queue-options.js +1 -0
  24. package/dist/jobs/computed-field-evaluation-queue-options.js.map +1 -1
  25. package/dist/jobs/database/chatter-queue-options-database.d.ts +8 -0
  26. package/dist/jobs/database/chatter-queue-options-database.d.ts.map +1 -0
  27. package/dist/jobs/database/chatter-queue-options-database.js +10 -0
  28. package/dist/jobs/database/chatter-queue-options-database.js.map +1 -0
  29. package/dist/jobs/database/chatter-queue-publisher-database.service.d.ts +12 -0
  30. package/dist/jobs/database/chatter-queue-publisher-database.service.d.ts.map +1 -0
  31. package/dist/jobs/database/chatter-queue-publisher-database.service.js +39 -0
  32. package/dist/jobs/database/chatter-queue-publisher-database.service.js.map +1 -0
  33. package/dist/jobs/database/chatter-queue-subscriber-database.service.d.ts +19 -0
  34. package/dist/jobs/database/chatter-queue-subscriber-database.service.d.ts.map +1 -0
  35. package/dist/jobs/database/chatter-queue-subscriber-database.service.js +62 -0
  36. package/dist/jobs/database/chatter-queue-subscriber-database.service.js.map +1 -0
  37. package/dist/services/chatter-message.service.d.ts +4 -4
  38. package/dist/services/chatter-message.service.d.ts.map +1 -1
  39. package/dist/services/chatter-message.service.js +33 -9
  40. package/dist/services/chatter-message.service.js.map +1 -1
  41. package/dist/services/queues/rabbitmq-publisher.service.d.ts +1 -0
  42. package/dist/services/queues/rabbitmq-publisher.service.d.ts.map +1 -1
  43. package/dist/services/queues/rabbitmq-publisher.service.js +6 -1
  44. package/dist/services/queues/rabbitmq-publisher.service.js.map +1 -1
  45. package/dist/services/queues/rabbitmq-subscriber.service.d.ts +1 -0
  46. package/dist/services/queues/rabbitmq-subscriber.service.d.ts.map +1 -1
  47. package/dist/services/queues/rabbitmq-subscriber.service.js +15 -4
  48. package/dist/services/queues/rabbitmq-subscriber.service.js.map +1 -1
  49. package/dist/services/request-context.service.d.ts +2 -1
  50. package/dist/services/request-context.service.d.ts.map +1 -1
  51. package/dist/services/request-context.service.js.map +1 -1
  52. package/dist/solid-core.module.d.ts.map +1 -1
  53. package/dist/solid-core.module.js +8 -0
  54. package/dist/solid-core.module.js.map +1 -1
  55. package/dist/subscribers/audit.subscriber.d.ts +8 -3
  56. package/dist/subscribers/audit.subscriber.d.ts.map +1 -1
  57. package/dist/subscribers/audit.subscriber.js +54 -52
  58. package/dist/subscribers/audit.subscriber.js.map +1 -1
  59. package/dist/subscribers/created-by-updated-by.subscriber.d.ts +0 -1
  60. package/dist/subscribers/created-by-updated-by.subscriber.d.ts.map +1 -1
  61. package/dist/subscribers/created-by-updated-by.subscriber.js +3 -13
  62. package/dist/subscribers/created-by-updated-by.subscriber.js.map +1 -1
  63. package/package.json +1 -1
  64. package/src/entities/mq-message-queue.entity.ts +8 -8
  65. package/src/helpers/bootstrap.helper.ts +1 -1
  66. package/src/helpers/cors.helper.ts +5 -1
  67. package/src/interfaces.ts +1 -0
  68. package/src/jobs/chatter-queue-options.ts +1 -1
  69. package/src/jobs/chatter-queue-publisher.service.ts +11 -11
  70. package/src/jobs/chatter-queue-subscriber.service.ts +13 -8
  71. package/src/jobs/computed-field-evaluation-queue-options.ts +1 -0
  72. package/src/jobs/database/chatter-queue-options-database.ts +9 -0
  73. package/src/jobs/database/chatter-queue-publisher-database.service.ts +24 -0
  74. package/src/jobs/database/chatter-queue-subscriber-database.service.ts +53 -0
  75. package/src/services/chatter-message.service.ts +41 -9
  76. package/src/services/queues/rabbitmq-publisher.service.ts +8 -2
  77. package/src/services/queues/rabbitmq-subscriber.service.ts +16 -5
  78. package/src/services/request-context.service.ts +2 -1
  79. package/src/solid-core.module.ts +8 -2
  80. package/src/subscribers/audit.subscriber.ts +59 -224
  81. package/src/subscribers/created-by-updated-by.subscriber.ts +22 -16
  82. package/logs_load_testing +0 -49
@@ -1 +1 @@
1
- {"version":3,"file":"rabbitmq-publisher.service.js","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-publisher.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyD;AACzD,8CAAgC;AAChC,+BAAoC;AAKpC,qCAAoD;AAEpD,MAAsB,iBAAiB;IAUnC,YACuB,gBAAkC,EAClC,qBAA4C;QAD5C,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAXlD,WAAM,GAAG,IAAI,eAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAKrD,eAAU,GAA2B,IAAI,CA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BAAgB,EAAE,cAAc,CAAC,EAAE;aACtC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;IAEL,CAAC;CACJ;AAxND,8CAwNC","sourcesContent":["import { Logger, OnModuleDestroy } from '@nestjs/common';\nimport * as amqp from 'amqplib';\nimport { v4 as uuidv4 } from 'uuid';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueuePublisher } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { buildNamespacedQueueName } from './common';\n\nexport abstract class RabbitMqPublisher<T> implements OnModuleDestroy, QueuePublisher<T> {\n private readonly logger = new Logger(RabbitMqPublisher.name);\n private readonly url: string;\n private readonly serviceRole: string;\n\n // Maintain connection...\n private connection: amqp.Connection | null = null;\n private channel: amqp.Channel | null = null;\n private connectingPromise: Promise<void> | null = null;\n\n constructor(\n protected readonly mqMessageService: MqMessageService,\n protected readonly mqMessageQueueService: MqMessageQueueService,\n ) {\n this.url = process.env.QUEUES_RABBIT_MQ_URL;\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.url) {\n this.logger.debug('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`RabbitMqPublisher instance created with options: ${JSON.stringify(this.options())} and url: ${this.url}`);\n }\n\n abstract options(): QueuesModuleOptions;\n\n private async ensureConnectionAndChannel(): Promise<amqp.Channel> {\n if (this.channel) {\n return this.channel;\n }\n\n // If another call is already connecting, wait for it\n if (this.connectingPromise) {\n await this.connectingPromise;\n if (this.channel) return this.channel;\n }\n\n this.connectingPromise = (async () => {\n const url = new URL(this.url);\n\n const conn = await amqp.connect({\n protocol: url.protocol.replace(':', ''), // \"amqps\"\n hostname: url.hostname,\n port: parseInt(url.port),\n username: url.username,\n // Node's URL already decodes percent-encoding; decodeURIComponent is not needed\n // But without it does not seem to be working...\n password: decodeURIComponent(url.password),\n frameMax: 131072,\n });\n\n conn.on('error', (err) => {\n this.logger.error(`RabbitMQ connection error: ${err.message}`, err.stack);\n });\n\n conn.on('close', () => {\n this.logger.warn('RabbitMQ connection closed, resetting');\n this.connection = null;\n this.channel = null;\n });\n\n const channel = await conn.createChannel();\n\n channel.on('return', (msg) => {\n const content = msg.content?.toString?.() ?? '';\n this.logger.warn(\n `RabbitMqPublisher message returned from exchange ${msg.fields.exchange} with routingKey ${msg.fields.routingKey}: ${content}`,\n );\n });\n\n const options = this.options();\n const queueName = options.queueName;\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n const exchangeName = `${namespacedQueueName}.exchange`;\n const routingKey = `${namespacedQueueName}.routing-key`;\n\n await channel.assertExchange(exchangeName, 'direct', {});\n const queue = await channel.assertQueue(namespacedQueueName, {});\n await channel.bindQueue(queue.queue, exchangeName, routingKey);\n\n this.connection = conn;\n this.channel = channel;\n })();\n\n try {\n await this.connectingPromise;\n } finally {\n this.connectingPromise = null;\n }\n\n if (!this.channel) {\n throw new Error('Failed to initialize RabbitMQ channel');\n }\n\n return this.channel;\n }\n\n // Nest will call this for every subclass instance, because they inherit the method\n async onModuleDestroy(): Promise<void> {\n await this.closeConnectionAndChannel();\n }\n\n private async closeConnectionAndChannel(): Promise<void> {\n if (this.channel) {\n try {\n await this.channel.close();\n } catch (err) {\n this.logger.warn(\n `RabbitMqPublisher error closing channel: ${(err as Error).message}`,\n );\n } finally {\n this.channel = null;\n }\n }\n\n if (this.connection) {\n try {\n await this.connection.close();\n } catch (err) {\n this.logger.warn(\n `RabbitMqPublisher error closing connection: ${(err as Error).message}`,\n );\n } finally {\n this.connection = null;\n }\n }\n }\n\n async publish(message: QueueMessage<T>): Promise<string> {\n if (!this.url) {\n this.logger.error('RabbitMqPublisher url is not defined in the environment variables');\n throw new Error('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.error('Queue service Role is not defined in the environment variables');\n throw new Error('Queue service Role is not defined in the environment variables');\n }\n if (this.serviceRole === 'subscriber') {\n this.logger.error('Queue service Role is subscriber, cannot publish messages');\n throw new Error('Queue service Role is subscriber, cannot publish messages');\n }\n\n const channel = await this.ensureConnectionAndChannel();\n // this.logger.debug(`RabbitMqPublisher publisher channel created options: ${JSON.stringify(this.options())} and url: ${url}`);\n\n const options = this.options();\n\n const queueName = options.queueName;\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n\n const exchangeName = `${namespacedQueueName}.exchange`;\n const routingKey = `${namespacedQueueName}.routing-key`;\n\n // Set default values for retry. \n // by default there are no retries.\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n\n // generate a new message id \n message.messageId = uuidv4();\n\n // Save the message to the DB so that we can then change its status in the subscriber...\n await this.persistToDatabase(namespacedQueueName, message);\n\n // wait for the channel to confirm \n try {\n // Publish the message\n // const publishStatus = channel.publish(exchangeName, routingKey, Buffer.from(JSON.stringify(message)));\n const publishStatus = channel.publish(exchangeName, routingKey, Buffer.from(JSON.stringify(message)), { mandatory: true });\n // this.logger.debug(`RabbitMqPublisher publish status: ${JSON.stringify(publishStatus)}`);\n // if (!publishStatus) {\n // this.logger.warn('RabbitMqPublisher Message buffering failed!');\n // }\n // await channel.waitForConfirms();\n // this.logger.debug('RabbitMqPublisher Message published successfully');\n } catch (err) {\n this.logger.error(`RabbitMqPublisher Message publish failed: ${JSON.stringify(err)}`);\n if (err instanceof Error) {\n this.logger.error(`RabbitMqPublisher Error stack: ${err.stack}`);\n }\n }\n finally {\n }\n // this.logger.debug(`Sent message: ${JSON.stringify(message)}`);\n\n // return the newly created message id.\n return message.messageId;\n }\n\n private async persistToDatabase(queueName: string, message: QueueMessage<T>) {\n\n // TODO: make an entry in the relevant database table, generate a unique id earlier.\n try {\n // 1. resolve the queue first\n const mqMessageQueue = await this.mqMessageQueueService.resolveQueue(queueName);\n\n // 2. Next create an entry in the mqMessage table. \n await this.mqMessageService.create({\n messageBroker: this.options().type,\n messageId: message.messageId,\n retryCount: message.retryCount,\n retryInterval: message.retryInterval,\n stage: 'pending',\n startedAt: new Date(),\n input: JSON.stringify(message, null, 2),\n parentEntityId: message.parentEntityId,\n parentEntity: message.parentEntity,\n mqMessageQueueId: mqMessageQueue.id,\n });\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n\n }\n}\n"]}
1
+ {"version":3,"file":"rabbitmq-publisher.service.js","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-publisher.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyD;AACzD,8CAAgC;AAChC,+BAAoC;AAKpC,qCAAoD;AAEpD,MAAsB,iBAAiB;IAUnC,YACuB,gBAAkC,EAClC,qBAA4C;QAD5C,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAXlD,WAAM,GAAG,IAAI,eAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAKrD,eAAU,GAA2B,IAAI,CAAC;QAC1C,YAAO,GAAwB,IAAI,CAAC;QACpC,sBAAiB,GAAyB,IAAI,CAAC;QAMnD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACxF,CAAC;IAE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 as uuidv4 } from 'uuid';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueuePublisher } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { buildNamespacedQueueName } from './common';\n\nexport abstract class RabbitMqPublisher<T> implements OnModuleDestroy, QueuePublisher<T> {\n private readonly logger = new Logger(RabbitMqPublisher.name);\n private readonly url: string;\n private readonly serviceRole: string;\n\n // Maintain connection...\n private connection: amqp.Connection | null = null;\n private channel: amqp.Channel | null = null;\n private connectingPromise: Promise<void> | null = null;\n\n constructor(\n protected readonly mqMessageService: MqMessageService,\n protected readonly mqMessageQueueService: MqMessageQueueService,\n ) {\n this.url = process.env.QUEUES_RABBIT_MQ_URL;\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.url) {\n this.logger.debug('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`RabbitMqPublisher instance created with options: ${JSON.stringify(this.options())} and url: ${this.url}`);\n }\n\n abstract options(): QueuesModuleOptions;\n\n protected shouldPersistToDatabase(): boolean {\n return this.options().persistToDatabase ?? true;\n }\n\n private async ensureConnectionAndChannel(): Promise<amqp.Channel> {\n if (this.channel) {\n return this.channel;\n }\n\n // If another call is already connecting, wait for it\n if (this.connectingPromise) {\n await this.connectingPromise;\n if (this.channel) return this.channel;\n }\n\n this.connectingPromise = (async () => {\n const url = new URL(this.url);\n\n const conn = await amqp.connect({\n protocol: url.protocol.replace(':', ''), // \"amqps\"\n hostname: url.hostname,\n port: parseInt(url.port),\n username: url.username,\n // Node's URL already decodes percent-encoding; decodeURIComponent is not needed\n // But without it does not seem to be working...\n password: decodeURIComponent(url.password),\n frameMax: 131072,\n });\n\n conn.on('error', (err) => {\n this.logger.error(`RabbitMQ connection error: ${err.message}`, err.stack);\n });\n\n conn.on('close', () => {\n this.logger.warn('RabbitMQ connection closed, resetting');\n this.connection = null;\n this.channel = null;\n });\n\n const channel = await conn.createChannel();\n\n channel.on('return', (msg) => {\n const content = msg.content?.toString?.() ?? '';\n this.logger.warn(\n `RabbitMqPublisher message returned from exchange ${msg.fields.exchange} with routingKey ${msg.fields.routingKey}: ${content}`,\n );\n });\n\n const options = this.options();\n const queueName = options.queueName;\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n const exchangeName = `${namespacedQueueName}.exchange`;\n const routingKey = `${namespacedQueueName}.routing-key`;\n\n await channel.assertExchange(exchangeName, 'direct', {});\n const queue = await channel.assertQueue(namespacedQueueName, {});\n await channel.bindQueue(queue.queue, exchangeName, routingKey);\n\n this.connection = conn;\n this.channel = channel;\n })();\n\n try {\n await this.connectingPromise;\n } finally {\n this.connectingPromise = null;\n }\n\n if (!this.channel) {\n throw new Error('Failed to initialize RabbitMQ channel');\n }\n\n return this.channel;\n }\n\n // Nest will call this for every subclass instance, because they inherit the method\n async onModuleDestroy(): Promise<void> {\n await this.closeConnectionAndChannel();\n }\n\n private async closeConnectionAndChannel(): Promise<void> {\n if (this.channel) {\n try {\n await this.channel.close();\n } catch (err) {\n this.logger.warn(\n `RabbitMqPublisher error closing channel: ${(err as Error).message}`,\n );\n } finally {\n this.channel = null;\n }\n }\n\n if (this.connection) {\n try {\n await this.connection.close();\n } catch (err) {\n this.logger.warn(\n `RabbitMqPublisher error closing connection: ${(err as Error).message}`,\n );\n } finally {\n this.connection = null;\n }\n }\n }\n\n async publish(message: QueueMessage<T>): Promise<string> {\n if (!this.url) {\n this.logger.error('RabbitMqPublisher url is not defined in the environment variables');\n throw new Error('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.error('Queue service Role is not defined in the environment variables');\n throw new Error('Queue service Role is not defined in the environment variables');\n }\n if (this.serviceRole === 'subscriber') {\n this.logger.error('Queue service Role is subscriber, cannot publish messages');\n throw new Error('Queue service Role is subscriber, cannot publish messages');\n }\n\n const channel = await this.ensureConnectionAndChannel();\n // this.logger.debug(`RabbitMqPublisher publisher channel created options: ${JSON.stringify(this.options())} and url: ${url}`);\n\n const options = this.options();\n\n const queueName = options.queueName;\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n\n const exchangeName = `${namespacedQueueName}.exchange`;\n const routingKey = `${namespacedQueueName}.routing-key`;\n\n // Set default values for retry. \n // by default there are no retries.\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n\n // generate a new message id \n message.messageId = uuidv4();\n\n // Save the message to the DB so that we can then change its status in the subscriber...\n if (this.shouldPersistToDatabase()) {\n await this.persistToDatabase(namespacedQueueName, message);\n }\n\n // wait for the channel to confirm \n try {\n // Publish the message\n // const publishStatus = channel.publish(exchangeName, routingKey, Buffer.from(JSON.stringify(message)));\n const publishStatus = channel.publish(exchangeName, routingKey, Buffer.from(JSON.stringify(message)), { mandatory: true });\n // this.logger.debug(`RabbitMqPublisher publish status: ${JSON.stringify(publishStatus)}`);\n // if (!publishStatus) {\n // this.logger.warn('RabbitMqPublisher Message buffering failed!');\n // }\n // await channel.waitForConfirms();\n // this.logger.debug('RabbitMqPublisher Message published successfully');\n } catch (err) {\n this.logger.error(`RabbitMqPublisher Message publish failed: ${JSON.stringify(err)}`);\n if (err instanceof Error) {\n this.logger.error(`RabbitMqPublisher Error stack: ${err.stack}`);\n }\n }\n finally {\n }\n // this.logger.debug(`Sent message: ${JSON.stringify(message)}`);\n\n // return the newly created message id.\n return message.messageId;\n }\n\n private async persistToDatabase(queueName: string, message: QueueMessage<T>) {\n\n // make an entry in the relevant database table, generate a unique id earlier.\n try {\n // 1. resolve the queue first\n const mqMessageQueue = await this.mqMessageQueueService.resolveQueue(queueName);\n\n // 2. Next create an entry in the mqMessage table. \n await this.mqMessageService.create({\n messageBroker: this.options().type,\n messageId: message.messageId,\n retryCount: message.retryCount,\n retryInterval: message.retryInterval,\n stage: 'pending',\n startedAt: new Date(),\n input: JSON.stringify(message, null, 2),\n parentEntityId: message.parentEntityId,\n parentEntity: message.parentEntity,\n mqMessageQueueId: mqMessageQueue.id,\n });\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n\n }\n}\n"]}
@@ -21,6 +21,7 @@ export declare abstract class RabbitMqSubscriber<T> implements OnModuleInit, Que
21
21
  protected get logger(): Logger;
22
22
  abstract subscribe(message: QueueMessage<T>): any;
23
23
  abstract options(): QueuesModuleOptions;
24
+ protected shouldPersistToDatabase(): boolean;
24
25
  establishConnection(): Promise<amqp.Connection>;
25
26
  onModuleInit(): Promise<void>;
26
27
  private connectAndConsume;
@@ -1 +1 @@
1
- {"version":3,"file":"rabbitmq-subscriber.service.d.ts","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-subscriber.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAezD,8BAAsB,kBAAkB,CAAC,CAAC,CAAE,YAAW,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;IAWvE,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB;IAAE,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB;IAVlI,OAAO,CAAC,eAAe,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OA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AI,CAAC;YAkBjG,sBAAsB;IAkCpC,OAAO,CAAC,0BAA0B;IAqBlC,OAAO,CAAC,gBAAgB;YASV,oBAAoB;CAuDrC"}
@@ -74,6 +74,9 @@ class RabbitMqSubscriber {
74
74
  }
75
75
  return this._loggerInstance;
76
76
  }
77
+ shouldPersistToDatabase() {
78
+ return this.options().persistToDatabase ?? true;
79
+ }
77
80
  async establishConnection() {
78
81
  const url = new URL(this.url);
79
82
  const connection = await amqp.connect({
@@ -218,7 +221,9 @@ class RabbitMqSubscriber {
218
221
  const errorMessage = error?.message || String(error);
219
222
  this.logger.error(`Error processing message on queue ${queueName}: ${errorMessage}`, error?.stack);
220
223
  if (message.currentRetry < message.retryCount) {
221
- await this.updateStatusInDatabase('retrying', message);
224
+ if (this.shouldPersistToDatabase()) {
225
+ await this.updateStatusInDatabase('retrying', message);
226
+ }
222
227
  message.currentRetry++;
223
228
  const retryQueue = `${queueName}.retry`;
224
229
  const payload = Buffer.from(JSON.stringify(message));
@@ -232,7 +237,9 @@ class RabbitMqSubscriber {
232
237
  this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms on queue ${queueName}`);
233
238
  return;
234
239
  }
235
- await this.updateStatusInDatabase('failed', message, errorMessage, '');
240
+ if (this.shouldPersistToDatabase()) {
241
+ await this.updateStatusInDatabase('failed', message, errorMessage, '');
242
+ }
236
243
  channel.ack(rawMessage);
237
244
  await this.publishToFailedQueue(queueName, Buffer.from(JSON.stringify(message)), channel, error);
238
245
  this.logger.error(`Message failed after ${message.retryCount} attempts on queue ${queueName}: ${errorMessage}`);
@@ -317,10 +324,14 @@ class RabbitMqSubscriber {
317
324
  return Math.min(maxMs, exp + jitter);
318
325
  }
319
326
  async processMessage(message, rawMessage, channel, queueName) {
320
- await this.updateStatusInDatabase('started', message);
327
+ if (this.shouldPersistToDatabase()) {
328
+ await this.updateStatusInDatabase('started', message);
329
+ }
321
330
  const result = await this.subscribeWithTimeout(message, queueName);
322
331
  channel.ack(rawMessage);
323
- await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');
332
+ if (this.shouldPersistToDatabase()) {
333
+ await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');
334
+ }
324
335
  }
325
336
  async updateStatusInDatabase(stage, message, error = '', result = '') {
326
337
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"rabbitmq-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-subscriber.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAsD;AACtD,8CAAgC;AAKhC,qCAAoD;AAEpD,MAAM,8BAA+B,SAAQ,KAAK;IAC9C,YACa,SAAiB,EACjB,SAAiB,EACjB,SAAiB;QAE1B,KAAK,CAAC,yCAAyC,SAAS,gBAAgB,SAAS,kBAAkB,SAAS,EAAE,CAAC,CAAC;QAJvG,cAAS,GAAT,SAAS,CAAQ;QACjB,cAAS,GAAT,SAAS,CAAQ;QACjB,cAAS,GAAT,SAAS,CAAQ;QAG1B,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IACjD,CAAC;CACJ;AAGD,MAAsB,kBAAkB;IAWpC,YAA+B,gBAAkC,EAAqB,qBAA4C;QAAnG,qBAAgB,GAAhB,gBAAgB,CAAkB;QAAqB,0BAAqB,GAArB,qBAAqB,CAAuB;QAP1H,eAAU,GAA2B,IAAI,CAAC;QAC1C,YAAO,GAAwB,IAAI,CAAC;QACpC,gBAAW,GAAkB,IAAI,CAAC;QAClC,qBAAgB,GAAyB,IAAI,CAAC;QAC9C,qBAAgB,GAAG,CAAC,CAAC;QACrB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACnD,IAAI,CAAC,I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SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;YAChF,CAAC,EAAE,SAAS,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC;YAKD,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC,CAAC;QAClE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,YAAY,GAAI,KAAe,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;YAChE,IAAI,CAAC,MAAM,CAAC,KAAK,CACb,yCAAyC,SAAS,kBAAkB,SAAS,KAAK,YAAY,EAAE,EAC/F,KAAe,EAAE,KAAK,CAC1B,CAAC;YACF,MAAM,KAAK,CAAC;QAChB,CAAC;gBAAS,CAAC;YAEP,IAAI,aAAa,EAAE,CAAC;gBAChB,YAAY,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;QACL,CAAC;IACL,CAAC;CAEJ;AArdD,gDAqdC","sourcesContent":["import { Logger, OnModuleInit } from '@nestjs/common';\nimport * as amqp from 'amqplib';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { buildNamespacedQueueName } from './common';\n\nclass ConsumerProcessingTimeoutError extends Error {\n constructor(\n readonly queueName: string,\n readonly messageId: string,\n readonly timeoutMs: number,\n ) {\n super(`Subscriber processing timed out after ${timeoutMs}ms for queue ${queueName} and messageId ${messageId}`);\n this.name = 'ConsumerProcessingTimeoutError';\n }\n}\n\n\nexport abstract class RabbitMqSubscriber<T> implements OnModuleInit, QueueSubscriber<T> { // TODO This can be made a generic type for better type visibility\n private _loggerInstance?: Logger;\n private readonly url: string;\n private readonly serviceRole: string;\n private connection: amqp.Connection | null = null;\n private channel: amqp.Channel | null = null;\n private consumerTag: string | null = null;\n private reconnectPromise: Promise<void> | null = null;\n private reconnectAttempt = 0;\n private stopping = false;\n\n constructor(protected readonly mqMessageService: MqMessageService, protected readonly mqMessageQueueService: MqMessageQueueService) {\n this.url = process.env.QUEUES_RABBIT_MQ_URL;\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.url) {\n this.logger.debug('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`RabbitMqSubscriber instance created with options: ${JSON.stringify(this.options())} and url: ${this.url}`);\n }\n\n protected get loggerContext(): string {\n return this.constructor.name;\n }\n\n protected get logger(): Logger {\n if (!this._loggerInstance) {\n this._loggerInstance = new Logger(this.loggerContext);\n }\n return this._loggerInstance;\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n async establishConnection(): Promise<amqp.Connection> {\n\n const url = new URL(this.url);\n\n // this.logger.debug(`user: ${url.username}`);\n // // just for local debug, don’t log in prod\n // this.logger.debug(`pass: ${url.password}`);\n // this.logger.debug(`path (vhost): ${url.pathname}`);\n\n const connection = await amqp.connect({\n protocol: url.protocol.replace(':', ''),\n hostname: url.hostname,\n port: parseInt(url.port),\n username: url.username,\n password: decodeURIComponent(url.password),\n frameMax: 131072,\n heartbeat: 30,\n });\n\n return connection\n }\n\n async onModuleInit(): Promise<void> {\n // Not using SettingService here as that will necessitate all implementors of RabbitMqSubscriber to also inject SettingService which is not ideal. \n // Instead we directly read the environment variables here.\n const defaultBroker = process.env.QUEUES_DEFAULT_BROKER || 'rabbitmq';\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n const queueNameRegex = (process.env.QUEUES_QUEUE_NAME_REGEX_TO_ENABLE || '').trim();\n const roleAllowed = ['both', 'subscriber'].includes(this.serviceRole);\n\n if (!roleAllowed) {\n this.logger.log(`RabbitMqSubscriber is disabled because QUEUES_SERVICE_ROLE is \"${this.serviceRole}\". Expected \"both\" or \"subscriber\".`);\n return;\n }\n\n // we will start subscriber only if the current service role is subscriber. \n if (this.url && solidCliRunning === \"false\" && defaultBroker === 'rabbitmq') {\n const options = this.options();\n const queueName = options.queueName;\n\n if (queueNameRegex && queueNameRegex !== \"all\") {\n try {\n const regex = new RegExp(queueNameRegex);\n if (!regex.test(queueName)) {\n this.logger.log(`RabbitMqSubscriber for queue ${queueName} is disabled because it does not match QUEUES_QUEUE_NAME_REGEX_TO_ENABLE=${queueNameRegex}`);\n return;\n }\n } catch (error) {\n this.logger.error(`Invalid QUEUES_QUEUE_NAME_REGEX_TO_ENABLE regex \"${queueNameRegex}\". Subscriber for queue ${queueName} will not start.`);\n return;\n }\n }\n\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n try {\n await this.connectAndConsume(namespacedQueueName);\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${namespacedQueueName}: ${(err as Error).message}`, (err as Error).stack);\n this.triggerReconnect(namespacedQueueName, 'initial connection failure');\n }\n\n this.logger.log(`RabbitMqSubscriber ready to consume messages: ${JSON.stringify(options)} and url: ${this.url}`);\n }\n }\n\n private async connectAndConsume(queueName: string): Promise<void> {\n await this.cleanup();\n this.logger.log(`RabbitMqSubscriber in connectAndConsume for queue: ${queueName} and url: ${this.url}`);\n\n const options = this.options();\n const prefetch = options.prefetch ?? 1;\n if (prefetch < 1) {\n throw new Error(`RabbitMqSubscriber prefetch must be >= 1 for queue ${queueName}`);\n }\n const processingTimeoutMs = this.resolveProcessingTimeoutMs();\n if (processingTimeoutMs > 0) {\n this.logger.log(`RabbitMqSubscriber using processing timeout ${processingTimeoutMs}ms for queue ${queueName}`);\n }\n\n let connection: amqp.Connection;\n try {\n connection = await this.establishConnection();\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${queueName}: ${(err as Error).message}`, (err as Error).stack);\n throw err;\n }\n\n this.connection = connection;\n\n connection.on('error', (err) => {\n if (connection !== this.connection) return;\n this.logger.error(`RabbitMqSubscriber connection error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n connection.on('close', () => {\n if (connection !== this.connection) return;\n this.logger.warn(`RabbitMqSubscriber connection closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'connection closed');\n });\n\n const channel = await connection.createChannel();\n this.channel = channel;\n\n channel.on('error', (err) => {\n if (channel !== this.channel) return;\n this.logger.error(`RabbitMqSubscriber channel error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n channel.on('close', () => {\n if (channel !== this.channel) return;\n this.logger.warn(`RabbitMqSubscriber channel closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'channel closed');\n });\n\n // Process one message at a time per consumer to avoid parallel work on the same subscriber instance.\n await channel.prefetch(prefetch);\n\n // Use a direct exchange with a stable routing key so retry DLX can route back to the main queue.\n const exchangeName = `${queueName}.exchange`;\n const routingKey = `${queueName}.routing-key`;\n const retryQueue = `${queueName}.retry`;\n const failedQueue = `${queueName}.failed`;\n\n await channel.assertExchange(exchangeName, 'direct', {});\n await channel.assertQueue(queueName, {});\n await channel.bindQueue(queueName, exchangeName, routingKey);\n\n // Retry queue uses DLX to route expired messages back to the main exchange/routing key.\n await channel.assertQueue(retryQueue, {\n arguments: {\n 'x-dead-letter-exchange': exchangeName,\n 'x-dead-letter-routing-key': routingKey,\n }\n });\n\n await channel.assertQueue(failedQueue, {});\n\n const consumeResult = await channel.consume(\n queueName,\n async (rawMessage) => {\n if (!rawMessage) {\n return;\n }\n\n let message: QueueMessage<T> = null;\n\n try {\n const messageContentString = rawMessage.content.toString();\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n this.logger.debug(`rabbitmq subscriber received message with id: ${message.messageId} for queue ${queueName}`);\n } catch (error) {\n this.logger.error(`Invalid JSON message on queue ${queueName}: ${(error as Error).message}`);\n await this.publishToFailedQueue(queueName, rawMessage.content, channel, error);\n channel.ack(rawMessage);\n return;\n }\n\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n try {\n await this.processMessage(message, rawMessage, channel, queueName);\n } catch (error) {\n await this.handleProcessingError(message, rawMessage, channel, error, queueName);\n }\n },\n // Explicit ack enables reliable processing and retry routing.\n { noAck: false },\n );\n\n this.consumerTag = consumeResult.consumerTag;\n }\n\n // Retry flow: update DB -> increment retry -> send to retry queue with per-message expiration -> ack original.\n private async handleProcessingError(message: QueueMessage<T>, rawMessage: amqp.ConsumeMessage, channel: amqp.Channel, error: any, queueName: string): Promise<void> {\n const errorMessage = (error as Error)?.message || String(error);\n this.logger.error(`Error processing message on queue ${queueName}: ${errorMessage}`, (error as Error)?.stack);\n\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n const retryQueue = `${queueName}.retry`;\n const payload = Buffer.from(JSON.stringify(message));\n\n // Per-message expiration keeps the message in the retry queue until TTL, then DLX routes it back.\n channel.sendToQueue(retryQueue, payload, {\n expiration: String(message.retryInterval || 1000),\n headers: {\n 'x-error': errorMessage,\n }\n });\n\n channel.ack(rawMessage);\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms on queue ${queueName}`);\n return;\n }\n\n await this.updateStatusInDatabase('failed', message, errorMessage, '');\n channel.ack(rawMessage);\n await this.publishToFailedQueue(queueName, Buffer.from(JSON.stringify(message)), channel, error);\n this.logger.error(`Message failed after ${message.retryCount} attempts on queue ${queueName}: ${errorMessage}`);\n }\n\n private async publishToFailedQueue(queueName: string, payload: Buffer | string, channel: amqp.Channel, error?: any): Promise<void> {\n const failedQueue = `${queueName}.failed`;\n const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);\n const errorMessage = (error as Error)?.message || String(error || '');\n\n try {\n channel.sendToQueue(failedQueue, body, errorMessage ? {\n headers: { 'x-error': errorMessage }\n } : undefined);\n } catch (err) {\n this.logger.error(`Failed to publish to failed queue ${failedQueue}: ${(err as Error).message}`);\n }\n }\n\n private triggerReconnect(queueName: string, reason: string) {\n if (this.stopping) return;\n if (this.reconnectPromise) return;\n\n this.reconnectPromise = this.reconnectLoop(queueName, reason)\n .finally(() => {\n this.reconnectPromise = null;\n });\n }\n\n // Reconnect with backoff to avoid hammering the broker during outages.\n private async reconnectLoop(queueName: string, reason: string): Promise<void> {\n this.logger.warn(`RabbitMqSubscriber reconnecting for queue ${queueName}: ${reason}`);\n\n while (!this.stopping) {\n try {\n await this.connectAndConsume(queueName);\n this.reconnectAttempt = 0;\n this.logger.log(`RabbitMqSubscriber reconnected for queue ${queueName}`);\n return;\n } catch (err) {\n this.reconnectAttempt += 1;\n const delay = this.backoff();\n this.logger.warn(`RabbitMqSubscriber reconnect failed for queue ${queueName}; retrying in ${delay}ms`);\n await this.sleep(delay);\n }\n }\n }\n\n private async cleanup(): Promise<void> {\n const channel = this.channel;\n const connection = this.connection;\n const consumerTag = this.consumerTag;\n\n this.channel = null;\n this.connection = null;\n this.consumerTag = null;\n\n if (channel) {\n try {\n if (consumerTag) {\n await channel.cancel(consumerTag);\n }\n } catch (_) {\n // ignore\n }\n\n try {\n await channel.close();\n } catch (_) {\n // ignore\n }\n }\n\n if (connection) {\n try {\n await connection.close();\n } catch (_) {\n // ignore\n }\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n\n // Exponential backoff with jitter, capped to 30s.\n private backoff(): number {\n const baseMs = 1000;\n const maxMs = 30_000;\n const exp = Math.min(maxMs, baseMs * Math.pow(2, this.reconnectAttempt));\n const jitter = Math.floor(Math.random() * (exp * 0.2));\n return Math.min(maxMs, exp + jitter);\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>, rawMessage, channel, queueName: string): Promise<void> {\n await this.updateStatusInDatabase('started', message);\n\n // Capture the results of handling the task.\n const result = await this.subscribeWithTimeout(message, queueName);\n\n // Ack the message. \n channel.ack(rawMessage);\n\n // Persist success output and timing.\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n\n // Update the existing message record by messageId; creation happens upstream.\n try {\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n\n }\n\n private resolveProcessingTimeoutMs(): number {\n // Broker-side delivery-ack timeout (ms). If not provided, assume RabbitMQ default\n // behavior used in this project: 30 minutes.\n // Example (RabbitMQ broker):\n // - Broker ack timeout: 30m => 1,800,000ms (QUEUES_RABBITMQ_CONSUMER_ACK_TIMEOUT_MS)\n // - App soft timeout should be slightly lower, e.g. 29m30s => 1,770,000ms\n // (QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS), so application code fails first,\n // records DB state/error, and avoids broker-forced channel close as primary failure signal.\n const brokerTimeoutMs = this.parsePositiveInt(process.env.QUEUES_RABBITMQ_CONSUMER_ACK_TIMEOUT_MS, 30 * 60 * 1000);\n\n // Soft timeout should fire *before* broker timeout so we can fail explicitly,\n // persist status/error, and avoid broker-forced channel closure as primary signal.\n // Keep at least 1s to avoid zero/negative values when broker timeout is very small.\n const defaultSoftTimeoutMs = Math.max(1_000, brokerTimeoutMs - 30_000);\n\n // Final timeout precedence:\n // 1) QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS (if valid positive int)\n // 2) Derived defaultSoftTimeoutMs (broker timeout - 30s)\n return this.parsePositiveInt(process.env.QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS, defaultSoftTimeoutMs);\n }\n\n private parsePositiveInt(value: string | undefined, fallback: number): number {\n // Shared env parsing helper:\n // - missing/invalid/non-positive => fallback\n // - valid positive integer => parsed value\n if (!value) return fallback;\n const parsed = Number.parseInt(value, 10);\n return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;\n }\n\n private async subscribeWithTimeout(message: QueueMessage<T>, queueName: string): Promise<any> {\n const timeoutMs = this.resolveProcessingTimeoutMs();\n const messageId = message?.messageId || 'unknown';\n\n // Allow an escape hatch: non-positive timeout means run without a soft timeout.\n if (timeoutMs <= 0) {\n return this.subscribe(message);\n }\n\n let timedOut = false;\n let timeoutHandle: NodeJS.Timeout | null = null;\n\n // Main subscriber work promise.\n // If timeout has already fired, suppress rethrow to avoid unhandled rejection noise\n // (the timeout error is already the authoritative failure we track).\n const subscribePromise = this.subscribe(message).catch((error) => {\n if (timedOut) {\n this.logger.error(\n `Subscriber promise rejected after timeout for queue ${queueName} and messageId ${messageId}: ${(error as Error)?.message || String(error)}`,\n (error as Error)?.stack,\n );\n return undefined;\n }\n throw error;\n });\n\n // Timeout promise rejects after timeoutMs with an explicit domain-specific error.\n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutHandle = setTimeout(() => {\n timedOut = true;\n reject(new ConsumerProcessingTimeoutError(queueName, messageId, timeoutMs));\n }, timeoutMs);\n });\n\n try {\n // Promise.race settles as soon as the *first* promise settles.\n // - If subscribePromise resolves/rejects first, we use that outcome.\n // - If timeoutPromise rejects first, we fail fast with timeout error.\n // This ensures we mark DB status via normal error handling before broker ack-timeout.\n return await Promise.race([subscribePromise, timeoutPromise]);\n } catch (error) {\n const errorMessage = (error as Error)?.message || String(error);\n this.logger.error(\n `Subscriber execution failed for queue ${queueName} and messageId ${messageId}: ${errorMessage}`,\n (error as Error)?.stack,\n );\n throw error;\n } finally {\n // Always clear timer once race settles to avoid timer leaks.\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n }\n }\n\n}\n"]}
1
+ {"version":3,"file":"rabbitmq-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-subscriber.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAsD;AACtD,8CAAgC;AAKhC,qCAAoD;AAEpD,MAAM,8BAA+B,SAAQ,KAAK;IAC9C,YACa,SAAiB,EACjB,SAAiB,EACjB,SAAiB;QAE1B,KAAK,CAAC,yCAAyC,SAAS,gBAAgB,SAAS,kBAAkB,SAAS,EAAE,CAAC,CAAC;QAJvG,cAAS,GAAT,SAAS,CAAQ;QACjB,cAAS,GAAT,SAAS,CAAQ;QACjB,cAAS,GAAT,SAAS,CAAQ;QAG1B,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IACjD,CAAC;CACJ;AAGD,MAAsB,kBAAkB;IAWpC,YAA+B,gBAAkC,EAAqB,qBAA4C;QAAnG,qBAAgB,GAAhB,gBAAgB,CAAkB;QAAqB,0BAAqB,GAArB,qBAAqB,CAAuB;QAP1H,eAAU,GAA2B,IAAI,CAAC;QAC1C,YAAO,GAAwB,IAAI,CAAC;QACpC,gBAAW,GAAkB,IAAI,CAAC;QAClC,qBAAgB,GAAyB,IAAI,CAAC;QAC9C,qBAAgB,GAAG,CAAC,CAAC;QACrB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gEAAgE,C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M,EAAE,EAAE;YACpD,aAAa,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,QAAQ,GAAG,IAAI,CAAC;gBAChB,MAAM,CAAC,IAAI,8BAA8B,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;YAChF,CAAC,EAAE,SAAS,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC;YAKD,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC,CAAC;QAClE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,YAAY,GAAI,KAAe,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;YAChE,IAAI,CAAC,MAAM,CAAC,KAAK,CACb,yCAAyC,SAAS,kBAAkB,SAAS,KAAK,YAAY,EAAE,EAC/F,KAAe,EAAE,KAAK,CAC1B,CAAC;YACF,MAAM,KAAK,CAAC;QAChB,CAAC;gBAAS,CAAC;YAEP,IAAI,aAAa,EAAE,CAAC;gBAChB,YAAY,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;QACL,CAAC;IACL,CAAC;CAEJ;AAheD,gDAgeC","sourcesContent":["import { Logger, OnModuleInit } from '@nestjs/common';\nimport * as amqp from 'amqplib';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { buildNamespacedQueueName } from './common';\n\nclass ConsumerProcessingTimeoutError extends Error {\n constructor(\n readonly queueName: string,\n readonly messageId: string,\n readonly timeoutMs: number,\n ) {\n super(`Subscriber processing timed out after ${timeoutMs}ms for queue ${queueName} and messageId ${messageId}`);\n this.name = 'ConsumerProcessingTimeoutError';\n }\n}\n\n\nexport abstract class RabbitMqSubscriber<T> implements OnModuleInit, QueueSubscriber<T> { // TODO This can be made a generic type for better type visibility\n private _loggerInstance?: Logger;\n private readonly url: string;\n private readonly serviceRole: string;\n private connection: amqp.Connection | null = null;\n private channel: amqp.Channel | null = null;\n private consumerTag: string | null = null;\n private reconnectPromise: Promise<void> | null = null;\n private reconnectAttempt = 0;\n private stopping = false;\n\n constructor(protected readonly mqMessageService: MqMessageService, protected readonly mqMessageQueueService: MqMessageQueueService) {\n this.url = process.env.QUEUES_RABBIT_MQ_URL;\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.url) {\n this.logger.debug('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`RabbitMqSubscriber instance created with options: ${JSON.stringify(this.options())} and url: ${this.url}`);\n }\n\n protected get loggerContext(): string {\n return this.constructor.name;\n }\n\n protected get logger(): Logger {\n if (!this._loggerInstance) {\n this._loggerInstance = new Logger(this.loggerContext);\n }\n return this._loggerInstance;\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n protected shouldPersistToDatabase(): boolean {\n return this.options().persistToDatabase ?? true;\n }\n\n async establishConnection(): Promise<amqp.Connection> {\n\n const url = new URL(this.url);\n\n // this.logger.debug(`user: ${url.username}`);\n // // just for local debug, don’t log in prod\n // this.logger.debug(`pass: ${url.password}`);\n // this.logger.debug(`path (vhost): ${url.pathname}`);\n\n const connection = await amqp.connect({\n protocol: url.protocol.replace(':', ''),\n hostname: url.hostname,\n port: parseInt(url.port),\n username: url.username,\n password: decodeURIComponent(url.password),\n frameMax: 131072,\n heartbeat: 30,\n });\n\n return connection\n }\n\n async onModuleInit(): Promise<void> {\n // Not using SettingService here as that will necessitate all implementors of RabbitMqSubscriber to also inject SettingService which is not ideal. \n // Instead we directly read the environment variables here.\n const defaultBroker = process.env.QUEUES_DEFAULT_BROKER || 'rabbitmq';\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n const queueNameRegex = (process.env.QUEUES_QUEUE_NAME_REGEX_TO_ENABLE || '').trim();\n const roleAllowed = ['both', 'subscriber'].includes(this.serviceRole);\n\n if (!roleAllowed) {\n this.logger.log(`RabbitMqSubscriber is disabled because QUEUES_SERVICE_ROLE is \"${this.serviceRole}\". Expected \"both\" or \"subscriber\".`);\n return;\n }\n\n // we will start subscriber only if the current service role is subscriber. \n if (this.url && solidCliRunning === \"false\" && defaultBroker === 'rabbitmq') {\n const options = this.options();\n const queueName = options.queueName;\n\n if (queueNameRegex && queueNameRegex !== \"all\") {\n try {\n const regex = new RegExp(queueNameRegex);\n if (!regex.test(queueName)) {\n this.logger.log(`RabbitMqSubscriber for queue ${queueName} is disabled because it does not match QUEUES_QUEUE_NAME_REGEX_TO_ENABLE=${queueNameRegex}`);\n return;\n }\n } catch (error) {\n this.logger.error(`Invalid QUEUES_QUEUE_NAME_REGEX_TO_ENABLE regex \"${queueNameRegex}\". Subscriber for queue ${queueName} will not start.`);\n return;\n }\n }\n\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n try {\n await this.connectAndConsume(namespacedQueueName);\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${namespacedQueueName}: ${(err as Error).message}`, (err as Error).stack);\n this.triggerReconnect(namespacedQueueName, 'initial connection failure');\n }\n\n this.logger.log(`RabbitMqSubscriber ready to consume messages: ${JSON.stringify(options)} and url: ${this.url}`);\n }\n }\n\n private async connectAndConsume(queueName: string): Promise<void> {\n await this.cleanup();\n this.logger.log(`RabbitMqSubscriber in connectAndConsume for queue: ${queueName} and url: ${this.url}`);\n\n const options = this.options();\n const prefetch = options.prefetch ?? 1;\n if (prefetch < 1) {\n throw new Error(`RabbitMqSubscriber prefetch must be >= 1 for queue ${queueName}`);\n }\n const processingTimeoutMs = this.resolveProcessingTimeoutMs();\n if (processingTimeoutMs > 0) {\n this.logger.log(`RabbitMqSubscriber using processing timeout ${processingTimeoutMs}ms for queue ${queueName}`);\n }\n\n let connection: amqp.Connection;\n try {\n connection = await this.establishConnection();\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${queueName}: ${(err as Error).message}`, (err as Error).stack);\n throw err;\n }\n\n this.connection = connection;\n\n connection.on('error', (err) => {\n if (connection !== this.connection) return;\n this.logger.error(`RabbitMqSubscriber connection error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n connection.on('close', () => {\n if (connection !== this.connection) return;\n this.logger.warn(`RabbitMqSubscriber connection closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'connection closed');\n });\n\n const channel = await connection.createChannel();\n this.channel = channel;\n\n channel.on('error', (err) => {\n if (channel !== this.channel) return;\n this.logger.error(`RabbitMqSubscriber channel error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n channel.on('close', () => {\n if (channel !== this.channel) return;\n this.logger.warn(`RabbitMqSubscriber channel closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'channel closed');\n });\n\n // Process one message at a time per consumer to avoid parallel work on the same subscriber instance.\n await channel.prefetch(prefetch);\n\n // Use a direct exchange with a stable routing key so retry DLX can route back to the main queue.\n const exchangeName = `${queueName}.exchange`;\n const routingKey = `${queueName}.routing-key`;\n const retryQueue = `${queueName}.retry`;\n const failedQueue = `${queueName}.failed`;\n\n await channel.assertExchange(exchangeName, 'direct', {});\n await channel.assertQueue(queueName, {});\n await channel.bindQueue(queueName, exchangeName, routingKey);\n\n // Retry queue uses DLX to route expired messages back to the main exchange/routing key.\n await channel.assertQueue(retryQueue, {\n arguments: {\n 'x-dead-letter-exchange': exchangeName,\n 'x-dead-letter-routing-key': routingKey,\n }\n });\n\n await channel.assertQueue(failedQueue, {});\n\n const consumeResult = await channel.consume(\n queueName,\n async (rawMessage) => {\n if (!rawMessage) {\n return;\n }\n\n let message: QueueMessage<T> = null;\n\n try {\n const messageContentString = rawMessage.content.toString();\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n this.logger.debug(`rabbitmq subscriber received message with id: ${message.messageId} for queue ${queueName}`);\n } catch (error) {\n this.logger.error(`Invalid JSON message on queue ${queueName}: ${(error as Error).message}`);\n await this.publishToFailedQueue(queueName, rawMessage.content, channel, error);\n channel.ack(rawMessage);\n return;\n }\n\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n try {\n await this.processMessage(message, rawMessage, channel, queueName);\n } catch (error) {\n await this.handleProcessingError(message, rawMessage, channel, error, queueName);\n }\n },\n // Explicit ack enables reliable processing and retry routing.\n { noAck: false },\n );\n\n this.consumerTag = consumeResult.consumerTag;\n }\n\n // Retry flow: update DB -> increment retry -> send to retry queue with per-message expiration -> ack original.\n private async handleProcessingError(message: QueueMessage<T>, rawMessage: amqp.ConsumeMessage, channel: amqp.Channel, error: any, queueName: string): Promise<void> {\n const errorMessage = (error as Error)?.message || String(error);\n this.logger.error(`Error processing message on queue ${queueName}: ${errorMessage}`, (error as Error)?.stack);\n\n if (message.currentRetry < message.retryCount) {\n if (this.shouldPersistToDatabase()) {\n await this.updateStatusInDatabase('retrying', message);\n }\n\n message.currentRetry++;\n const retryQueue = `${queueName}.retry`;\n const payload = Buffer.from(JSON.stringify(message));\n\n // Per-message expiration keeps the message in the retry queue until TTL, then DLX routes it back.\n channel.sendToQueue(retryQueue, payload, {\n expiration: String(message.retryInterval || 1000),\n headers: {\n 'x-error': errorMessage,\n }\n });\n\n channel.ack(rawMessage);\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms on queue ${queueName}`);\n return;\n }\n if (this.shouldPersistToDatabase()) {\n await this.updateStatusInDatabase('failed', message, errorMessage, '');\n }\n channel.ack(rawMessage);\n await this.publishToFailedQueue(queueName, Buffer.from(JSON.stringify(message)), channel, error);\n this.logger.error(`Message failed after ${message.retryCount} attempts on queue ${queueName}: ${errorMessage}`);\n }\n\n private async publishToFailedQueue(queueName: string, payload: Buffer | string, channel: amqp.Channel, error?: any): Promise<void> {\n const failedQueue = `${queueName}.failed`;\n const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);\n const errorMessage = (error as Error)?.message || String(error || '');\n\n try {\n channel.sendToQueue(failedQueue, body, errorMessage ? {\n headers: { 'x-error': errorMessage }\n } : undefined);\n } catch (err) {\n this.logger.error(`Failed to publish to failed queue ${failedQueue}: ${(err as Error).message}`);\n }\n }\n\n private triggerReconnect(queueName: string, reason: string) {\n if (this.stopping) return;\n if (this.reconnectPromise) return;\n\n this.reconnectPromise = this.reconnectLoop(queueName, reason)\n .finally(() => {\n this.reconnectPromise = null;\n });\n }\n\n // Reconnect with backoff to avoid hammering the broker during outages.\n private async reconnectLoop(queueName: string, reason: string): Promise<void> {\n this.logger.warn(`RabbitMqSubscriber reconnecting for queue ${queueName}: ${reason}`);\n\n while (!this.stopping) {\n try {\n await this.connectAndConsume(queueName);\n this.reconnectAttempt = 0;\n this.logger.log(`RabbitMqSubscriber reconnected for queue ${queueName}`);\n return;\n } catch (err) {\n this.reconnectAttempt += 1;\n const delay = this.backoff();\n this.logger.warn(`RabbitMqSubscriber reconnect failed for queue ${queueName}; retrying in ${delay}ms`);\n await this.sleep(delay);\n }\n }\n }\n\n private async cleanup(): Promise<void> {\n const channel = this.channel;\n const connection = this.connection;\n const consumerTag = this.consumerTag;\n\n this.channel = null;\n this.connection = null;\n this.consumerTag = null;\n\n if (channel) {\n try {\n if (consumerTag) {\n await channel.cancel(consumerTag);\n }\n } catch (_) {\n // ignore\n }\n\n try {\n await channel.close();\n } catch (_) {\n // ignore\n }\n }\n\n if (connection) {\n try {\n await connection.close();\n } catch (_) {\n // ignore\n }\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n\n // Exponential backoff with jitter, capped to 30s.\n private backoff(): number {\n const baseMs = 1000;\n const maxMs = 30_000;\n const exp = Math.min(maxMs, baseMs * Math.pow(2, this.reconnectAttempt));\n const jitter = Math.floor(Math.random() * (exp * 0.2));\n return Math.min(maxMs, exp + jitter);\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>, rawMessage, channel, queueName: string): Promise<void> {\n if (this.shouldPersistToDatabase()) {\n await this.updateStatusInDatabase('started', message);\n }\n\n // Capture the results of handling the task.\n const result = await this.subscribeWithTimeout(message, queueName);\n\n // Ack the message. \n channel.ack(rawMessage);\n\n // Persist success output and timing.\n if (this.shouldPersistToDatabase()) {\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n }\n\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n\n // Update the existing message record by messageId; creation happens upstream.\n try {\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n\n }\n\n private resolveProcessingTimeoutMs(): number {\n // Broker-side delivery-ack timeout (ms). If not provided, assume RabbitMQ default\n // behavior used in this project: 30 minutes.\n // Example (RabbitMQ broker):\n // - Broker ack timeout: 30m => 1,800,000ms (QUEUES_RABBITMQ_CONSUMER_ACK_TIMEOUT_MS)\n // - App soft timeout should be slightly lower, e.g. 29m30s => 1,770,000ms\n // (QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS), so application code fails first,\n // records DB state/error, and avoids broker-forced channel close as primary failure signal.\n const brokerTimeoutMs = this.parsePositiveInt(process.env.QUEUES_RABBITMQ_CONSUMER_ACK_TIMEOUT_MS, 30 * 60 * 1000);\n\n // Soft timeout should fire *before* broker timeout so we can fail explicitly,\n // persist status/error, and avoid broker-forced channel closure as primary signal.\n // Keep at least 1s to avoid zero/negative values when broker timeout is very small.\n const defaultSoftTimeoutMs = Math.max(1_000, brokerTimeoutMs - 30_000);\n\n // Final timeout precedence:\n // 1) QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS (if valid positive int)\n // 2) Derived defaultSoftTimeoutMs (broker timeout - 30s)\n return this.parsePositiveInt(process.env.QUEUES_RABBITMQ_SUBSCRIBER_PROCESSING_TIMEOUT_MS, defaultSoftTimeoutMs);\n }\n\n private parsePositiveInt(value: string | undefined, fallback: number): number {\n // Shared env parsing helper:\n // - missing/invalid/non-positive => fallback\n // - valid positive integer => parsed value\n if (!value) return fallback;\n const parsed = Number.parseInt(value, 10);\n return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;\n }\n\n private async subscribeWithTimeout(message: QueueMessage<T>, queueName: string): Promise<any> {\n const timeoutMs = this.resolveProcessingTimeoutMs();\n const messageId = message?.messageId || 'unknown';\n\n // Allow an escape hatch: non-positive timeout means run without a soft timeout.\n if (timeoutMs <= 0) {\n return this.subscribe(message);\n }\n\n let timedOut = false;\n let timeoutHandle: NodeJS.Timeout | null = null;\n\n // Main subscriber work promise.\n // If timeout has already fired, suppress rethrow to avoid unhandled rejection noise\n // (the timeout error is already the authoritative failure we track).\n const subscribePromise = this.subscribe(message).catch((error) => {\n if (timedOut) {\n this.logger.error(\n `Subscriber promise rejected after timeout for queue ${queueName} and messageId ${messageId}: ${(error as Error)?.message || String(error)}`,\n (error as Error)?.stack,\n );\n return undefined;\n }\n throw error;\n });\n\n // Timeout promise rejects after timeoutMs with an explicit domain-specific error.\n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutHandle = setTimeout(() => {\n timedOut = true;\n reject(new ConsumerProcessingTimeoutError(queueName, messageId, timeoutMs));\n }, timeoutMs);\n });\n\n try {\n // Promise.race settles as soon as the *first* promise settles.\n // - If subscribePromise resolves/rejects first, we use that outcome.\n // - If timeoutPromise rejects first, we fail fast with timeout error.\n // This ensures we mark DB status via normal error handling before broker ack-timeout.\n return await Promise.race([subscribePromise, timeoutPromise]);\n } catch (error) {\n const errorMessage = (error as Error)?.message || String(error);\n this.logger.error(\n `Subscriber execution failed for queue ${queueName} and messageId ${messageId}: ${errorMessage}`,\n (error as Error)?.stack,\n );\n throw error;\n } finally {\n // Always clear timer once race settles to avoid timer leaks.\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n }\n }\n\n}\n"]}
@@ -1,9 +1,10 @@
1
1
  import { ClsService } from "nestjs-cls";
2
2
  import { BasicFilterDto } from "src/dtos/basic-filters.dto";
3
+ import { ActiveUserData } from "src/interfaces/active-user-data.interface";
3
4
  export declare class RequestContextService {
4
5
  private readonly cls;
5
6
  constructor(cls: ClsService);
6
- getActiveUser(): any;
7
+ getActiveUser(): ActiveUserData | undefined;
7
8
  getIp(): string | undefined;
8
9
  getUserAgent(): string | undefined;
9
10
  setRequestFilter(filter: BasicFilterDto): void;
@@ -1 +1 @@
1
- {"version":3,"file":"request-context.service.d.ts","sourceRoot":"","sources":["../../src/services/request-context.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,qBACa,qBAAqB;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,UAAU;IAI5C,aAAa;IAIb,KAAK,IAAI,MAAM,GAAG,SAAS;IAI3B,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC,gBAAgB,CAAC,MAAM,EAAE,cAAc;IAIvC,gBAAgB,IAAI,cAAc,GAAG,SAAS;CAIjD"}
1
+ {"version":3,"file":"request-context.service.d.ts","sourceRoot":"","sources":["../../src/services/request-context.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAE3E,qBACa,qBAAqB;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,UAAU;IAI5C,aAAa,IAAI,cAAc,GAAG,SAAS;IAI3C,KAAK,IAAI,MAAM,GAAG,SAAS;IAI3B,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC,gBAAgB,CAAC,MAAM,EAAE,cAAc;IAIvC,gBAAgB,IAAI,cAAc,GAAG,SAAS;CAIjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"request-context.service.js","sourceRoot":"","sources":["../../src/services/request-context.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAAwC;AACxC,4CAAiD;AAI1C,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAC9B,YAA6B,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;IAC5C,CAAC;IAGD,aAAa;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,4BAAgB,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACrC,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB,CAAC,MAAsB;QACnC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,gBAAgB;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;CAEJ,CAAA;AAzBY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAEyB,uBAAU;GADnC,qBAAqB,CAyBjC","sourcesContent":["import { Injectable } from \"@nestjs/common\";\nimport { ClsService } from \"nestjs-cls\";\nimport { REQUEST_USER_KEY } from \"src/constants\";\nimport { BasicFilterDto } from \"src/dtos/basic-filters.dto\";\n\n@Injectable()\nexport class RequestContextService {\n constructor(private readonly cls: ClsService) {\n }\n\n // This method i.e getActiveUser() will fetch the user from the request object in the context\n getActiveUser() {\n return this.cls.get(REQUEST_USER_KEY);\n }\n\n getIp(): string | undefined {\n return this.cls.get('ipAddress');\n }\n\n getUserAgent(): string | undefined {\n return this.cls.get('userAgent');\n }\n\n setRequestFilter(filter: BasicFilterDto) {\n this.cls.set('filter', filter);\n }\n\n getRequestFilter(): BasicFilterDto | undefined {\n return this.cls.get('filter');\n }\n\n}"]}
1
+ {"version":3,"file":"request-context.service.js","sourceRoot":"","sources":["../../src/services/request-context.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAAwC;AACxC,4CAAiD;AAK1C,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAC9B,YAA6B,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;IAC5C,CAAC;IAGD,aAAa;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,4BAAgB,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACrC,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB,CAAC,MAAsB;QACnC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,gBAAgB;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;CAEJ,CAAA;AAzBY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAEyB,uBAAU;GADnC,qBAAqB,CAyBjC","sourcesContent":["import { Injectable } from \"@nestjs/common\";\nimport { ClsService } from \"nestjs-cls\";\nimport { REQUEST_USER_KEY } from \"src/constants\";\nimport { BasicFilterDto } from \"src/dtos/basic-filters.dto\";\nimport { ActiveUserData } from \"src/interfaces/active-user-data.interface\";\n\n@Injectable()\nexport class RequestContextService {\n constructor(private readonly cls: ClsService) {\n }\n\n // This method i.e getActiveUser() will fetch the user from the request object in the context\n getActiveUser(): ActiveUserData | undefined {\n return this.cls.get(REQUEST_USER_KEY);\n }\n\n getIp(): string | undefined {\n return this.cls.get('ipAddress');\n }\n\n getUserAgent(): string | undefined {\n return this.cls.get('userAgent');\n }\n\n setRequestFilter(filter: BasicFilterDto) {\n this.cls.set('filter', filter);\n }\n\n getRequestFilter(): BasicFilterDto | undefined {\n return this.cls.get('filter');\n }\n\n}"]}
@@ -1 +1 @@
1
- {"version":3,"file":"solid-core.module.d.ts","sourceRoot":"","sources":["../src/solid-core.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,kBAAkB,EAAU,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAsVhF,qBAkca,eAAgB,YAAW,UAAU;IAChD,SAAS,CAAC,QAAQ,EAAE,kBAAkB;CAKvC"}
1
+ {"version":3,"file":"solid-core.module.d.ts","sourceRoot":"","sources":["../src/solid-core.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,kBAAkB,EAAU,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA0VhF,qBAoca,eAAgB,YAAW,UAAU;IAChD,SAAS,CAAC,QAAQ,EAAE,kBAAkB;CAKvC"}
@@ -123,6 +123,10 @@ const msg91_sms_publisher_service_1 = require("./jobs/msg91-sms-publisher.servic
123
123
  const msg91_sms_subscriber_service_1 = require("./jobs/msg91-sms-subscriber.service");
124
124
  const smtp_email_publisher_service_1 = require("./jobs/smtp-email-publisher.service");
125
125
  const smtp_email_subscriber_service_1 = require("./jobs/smtp-email-subscriber.service");
126
+ const chatter_queue_publisher_service_1 = require("./jobs/chatter-queue-publisher.service");
127
+ const chatter_queue_subscriber_service_1 = require("./jobs/chatter-queue-subscriber.service");
128
+ const chatter_queue_publisher_database_service_1 = require("./jobs/database/chatter-queue-publisher-database.service");
129
+ const chatter_queue_subscriber_database_service_1 = require("./jobs/database/chatter-queue-subscriber-database.service");
126
130
  const test_queue_publisher_service_1 = require("./jobs/test-queue-publisher.service");
127
131
  const test_queue_subscriber_service_1 = require("./jobs/test-queue-subscriber.service");
128
132
  const user_registration_listener_1 = require("./listeners/user-registration.listener");
@@ -608,6 +612,10 @@ exports.SolidCoreModule = SolidCoreModule = __decorate([
608
612
  user_registration_listener_1.UserRegistrationListener,
609
613
  test_queue_publisher_service_1.TestQueuePublisher,
610
614
  test_queue_subscriber_service_1.TestQueueSubscriber,
615
+ chatter_queue_publisher_service_1.ChatterQueuePublisherRabbitmq,
616
+ chatter_queue_subscriber_service_1.ChatterQueueSubscriberRabbitmq,
617
+ chatter_queue_publisher_database_service_1.ChatterQueuePublisherDatabase,
618
+ chatter_queue_subscriber_database_service_1.ChatterQueueSubscriberDatabase,
611
619
  test_queue_publisher_database_service_1.TestQueuePublisherDatabase,
612
620
  test_queue_subscriber_database_service_1.TestQueueSubscriberDatabase,
613
621
  generate_code_publisher_database_service_1.GenerateCodePublisherDatabase,