message-brokers 1.10.2-beta → 1.11.0-beta.1

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/README.md CHANGED
@@ -180,6 +180,75 @@ messageBrokers.publishNotificationMessagesLogs(notification_messages_logs);
180
180
  // Publish amqp_lab_api_response
181
181
  messageBrokers.publishAmqpLabApiResponse(amqp_lab_api_response);
182
182
 
183
+ // Publish merged_lab_api_response
184
+ messageBrokers.publishAmqpMergedLabApiResponse(merged_lab_api_response);
185
+
183
186
  // Publish billing_events
184
187
  messageBrokers.publishBillingEvents(billing_events);
188
+
189
+ // Publish past data reminder request (hvconnect → LLM reminder app)
190
+ messageBrokers.publishPastDataReminderRequest(reminder_request);
191
+
192
+ // Publish prepared past data reminder message (LLM reminder app → hv-connect)
193
+ messageBrokers.publishPastDataReminderMessage(reminder_message);
194
+ ```
195
+
196
+ ## Publish options
197
+
198
+ Every publish method takes an optional last argument `options` (since 1.11.0). Everything is off by default: a call without options behaves as before, except that the message now gets a `message_id`.
199
+
200
+ ```javascript
201
+ const res = await messageBrokers.publishBillingEvents(billing_events, {
202
+ messageId: "…", // optional: use this id instead of a generated one
203
+ retry: true, // optional: this is a re-send of a deadqueue row
204
+ waitForConfirm: true, // optional: wait for the broker's publisher confirm
205
+ confirmTimeoutMs: 10000, // optional: how long to wait for the confirm
206
+ });
207
+ // res: { success, message, data, message_id, outcome: "published" | "failed" | "unconfirmed" }
208
+ ```
209
+
210
+ ### message_id
211
+
212
+ Every publish gets a `message_id`: `options.messageId`, else `crypto.randomUUID()`. It is sent as the AMQP `messageId` property (consumers can use it to drop a message they have already processed) and is returned as `res.message_id`.
213
+
214
+ ### Deadqueue rows
215
+
216
+ A failed publish is stored in the `deadqueue` collection as before, with these extra fields:
217
+
218
+ | Field | Meaning |
219
+ |---|---|
220
+ | `message_id` | the message's id |
221
+ | `status` | `failed`, `unconfirmed` (confirm timed out) or `published` (a retry succeeded) |
222
+ | `attempts` | publishes of this message so far, the first send included |
223
+ | `last_failed_at` | time of the latest failure |
224
+ | `failures` | `[{ at, failureMessage, reason }]`, the latest 10 |
225
+ | `published_at` | set when a retry succeeds |
226
+
227
+ ### Retrying a deadqueue row
228
+
229
+ The app reads the row and calls the same publish method with the row's `message` and `{ messageId: row.message_id, retry: true }`:
230
+
231
+ - failure → the same row is updated (`attempts` +1, `status`, `last_failed_at`, `failures`), no new row is inserted;
232
+ - success → the row becomes `status: "published"` (`attempts` +1, `published_at`).
233
+
234
+ How often and when to retry is up to the app; the package does not retry on its own. A first send whose `messageId` is already stored is handled like a retry, provided the app has a unique index:
235
+
236
+ ```javascript
237
+ db.deadqueue.createIndex(
238
+ { app_name: 1, message_id: 1 },
239
+ { unique: true, partialFilterExpression: { message_id: { $type: "string" } } }
240
+ );
185
241
  ```
242
+
243
+ ### waitForConfirm
244
+
245
+ The channel is a confirm channel. Without `waitForConfirm` the publish answers as soon as the message is written to the socket, and a `false` return from `channel.publish()` (write buffer full) counts as a failure even though the message is still sent, so a retry of that row would deliver it twice.
246
+
247
+ With `waitForConfirm: true` the publish waits for the broker's confirm:
248
+
249
+ - ack → `published`;
250
+ - nack, or the channel closing before the confirm → `failed` (stored as `failed`);
251
+ - no confirm within `confirmTimeoutMs` (default 10 s) → `unconfirmed` (stored as `unconfirmed`): the message may or may not have reached the broker, so it should not be re-sent automatically;
252
+ - a `false` return from `channel.publish()` is ignored: only the confirm decides.
253
+
254
+ The confirm only means the broker took the message. A message that no queue is bound to is still dropped and reported as `published`.
@@ -1,12 +1,12 @@
1
1
  const mbConfigs = {
2
2
  rabbitmqUrl: process.env.RABBITMQ_URL,
3
- centralRabbitmqUrl: process.env.CENTRAL_RABBITMQ_URL,
4
3
  activeMessageBroker: process.env.ACTIVE_MESSAGE_BROKER || "rabbitmq",
5
4
  redisPort: process.env.REDIS_PORT || 6260,
6
5
  cachingEnabled: process.env.CACHING_ENABLED || false,
7
6
  // Queues that are used in env where multiple instances of same stack share the same rabbitmq.
8
7
  // To avoid messages between different instances, we are isolating the queues.
9
- rabbitmqIsolatedQueues: ["messaging.har.lab-api.queue", "billing.events"],
10
- rabbitmqIsolatedRoutingKeys: ["har.lab_api_response", "billing"]
8
+ rabbitmqIsolatedQueues: ["messaging.har.lab-api.queue", "billing.events", "llm-reminder.past-data.queue", "messaging.past-data.reminder-message.queue"],
9
+ // Matched by prefix: "past_data." covers past_data.reminder_request and past_data.reminder_message.
10
+ rabbitmqIsolatedRoutingKeys: ["har.lab_api_response", "billing", "past_data."]
11
11
  };
12
12
  module.exports = mbConfigs;
@@ -20,10 +20,22 @@ const mqConfigs = [{
20
20
  queueName: "v2.lab-data.queue",
21
21
  routingKeyList: ["lab_api_response.amqp"],
22
22
  priorityQueue: false
23
+ }, {
24
+ queueName: "v2.merged-lab-data.queue",
25
+ routingKeyList: ["merged_lab_api_response.amqp"],
26
+ priorityQueue: false
23
27
  }, {
24
28
  queueName: "billing.events",
25
29
  routingKeyList: ["billing"],
26
30
  priorityQueue: false
31
+ }, {
32
+ queueName: "llm-reminder.past-data.queue",
33
+ routingKeyList: ["past_data.reminder_request"],
34
+ priorityQueue: false
35
+ }, {
36
+ queueName: "messaging.past-data.reminder-message.queue",
37
+ routingKeyList: ["past_data.reminder_message"],
38
+ priorityQueue: false
27
39
  }
28
40
  // Example for priority queue.
29
41
  // {
@@ -1,87 +1,105 @@
1
+ const {
2
+ randomUUID
3
+ } = require("crypto");
1
4
  const MessageBroker = require("../helpers/message-brokers.helper");
2
5
  const CacheService = require("../services/cache.service");
3
6
  const DeadQueueService = require("../services/deadqueue.service");
4
7
  const mbConfigs = require("../configs/mb.configs");
5
- const maskPid = require("../utils/maskPid");
6
- const CentralRabbitMQHelper = require("../rabbitmq/centralRabbitmq/centralRabbitmq.helper");
7
8
  const AmqpController = {};
8
9
 
9
10
  /**
10
11
  * Publishes a message to the specified exchange with a given routing key and priority.
11
12
  *
12
- * This function interacts with the MessageBroker instance to send messages
13
- * to a message broker (e.g., RabbitMQ). It returns a structured response indicating
14
- * whether the message was successfully published or if an error occurred.
13
+ * Every message gets a message_id (options.messageId, else a random UUID), sent as the AMQP
14
+ * messageId and stored with the message in the deadqueue when the publish fails.
15
15
  *
16
16
  * @param {string} exchange - The name of the exchange to publish the message to.
17
17
  * @param {string} routingKey - The routing key used for message routing.
18
18
  * @param {Object|string} message - The message payload to be published. Can be an object or a string.
19
19
  * @param {number} [priority=1] - (Optional) The priority level of the message. Defaults to 1.
20
+ * @param {Object} [options] - (Optional) Publish options, all off by default:
21
+ * - `messageId` (string): use this id instead of generating one (a retry passes the stored one).
22
+ * - `retry` (boolean): this is a re-send of a deadqueue row: a failure updates that row
23
+ * (attempts +1) instead of inserting a new one, a success marks it "published".
24
+ * - `waitForConfirm` (boolean): wait for the broker confirm before answering.
25
+ * - `confirmTimeoutMs` (number): how long to wait for the confirm (default 10000).
20
26
  *
21
27
  * @returns {Promise<Object>} - A promise that resolves to an object containing:
22
28
  * - `success` (boolean): Indicates if the message was successfully published.
23
29
  * - `message` (string): A descriptive message about the operation's outcome.
24
30
  * - `data` (any): Additional data related to the operation or error details if the operation failed.
31
+ * - `message_id` (string): The message's id (AMQP messageId, deadqueue message_id).
32
+ * - `outcome` (string): "published", "failed" or "unconfirmed" (confirm timed out).
25
33
  *
26
34
  */
27
- AmqpController.publishMessage = async (exchange, routingKey, message, priority = 1) => {
35
+ AmqpController.publishMessage = async (exchange, routingKey, message, priority = 1, options = {}) => {
36
+ const messageId = options.messageId || randomUUID();
37
+ const retry = options.retry === true;
38
+ const storeFailure = (failureMessage, errorObject, reason, status = "failed") => DeadQueueService.storeFailureMessage({
39
+ exchange,
40
+ routingKey,
41
+ message,
42
+ priority,
43
+ failureMessage,
44
+ errorObject,
45
+ reason
46
+ }, {
47
+ messageId,
48
+ retry,
49
+ status
50
+ });
28
51
  if (!mbConfigs.rabbitmqUrl) {
29
- await DeadQueueService.storeFailureMessage({
30
- exchange,
31
- routingKey,
32
- message,
33
- priority,
34
- failureMessage: "No rabbitmq url found."
35
- });
52
+ await storeFailure("No rabbitmq url found.", undefined, "No rabbitmq url found.");
36
53
  return {
37
54
  success: false,
38
55
  message: "RABBITMQ_URL is required for message brokers initialization.",
39
- data: null
56
+ data: null,
57
+ message_id: messageId,
58
+ outcome: "failed"
40
59
  };
41
60
  }
42
61
  try {
43
62
  const {
44
63
  error,
45
64
  message: msg,
46
- data
47
- } = await MessageBroker.publish(exchange, routingKey, message, priority);
65
+ data,
66
+ outcome = error ? "failed" : "published",
67
+ reason
68
+ } = await MessageBroker.publish(exchange, routingKey, message, priority, null, {
69
+ messageId,
70
+ waitForConfirm: options.waitForConfirm === true,
71
+ confirmTimeoutMs: options.confirmTimeoutMs
72
+ });
48
73
  if (!error) {
49
74
  console.log(`INFO: [${new Date().toLocaleString()}] [MQ]: ${routingKey} successfully published into the exchange.`);
75
+ if (retry) await DeadQueueService.markPublished(messageId);
50
76
  return {
51
77
  success: true,
52
78
  message: msg,
53
- data
79
+ data,
80
+ message_id: messageId,
81
+ outcome
54
82
  };
55
83
  } else {
56
84
  console.log(`ERROR: [${new Date().toLocaleString()}] [MQ]: Error while publishing ${routingKey} into the exchange.`);
57
- await DeadQueueService.storeFailureMessage({
58
- exchange,
59
- routingKey,
60
- message,
61
- priority,
62
- failureMessage: "Error while publishing into rabbitmq.",
63
- errorObject: error
64
- });
85
+ await storeFailure(outcome === "unconfirmed" ? "No broker confirm received in time." : "Error while publishing into rabbitmq.", error, reason, outcome);
65
86
  return {
66
87
  success: false,
67
88
  message: msg,
68
- data: `${error}`
89
+ data: `${error}`,
90
+ message_id: messageId,
91
+ outcome
69
92
  };
70
93
  }
71
94
  } catch (error) {
72
95
  console.log(`ERROR: [${new Date().toLocaleString()}] [MQ]: Error while publishing ${routingKey} into the exchange.`);
73
- await DeadQueueService.storeFailureMessage({
74
- exchange,
75
- routingKey,
76
- message,
77
- priority,
78
- failureMessage: "Unexpected error while publishing into rabbitmq.",
79
- errorObject: error
80
- });
96
+ await storeFailure("Unexpected error while publishing into rabbitmq.", error, error?.message);
81
97
  return {
82
98
  success: false,
83
99
  message: `Error publishing ${routingKey}`,
84
- data: error
100
+ data: error,
101
+ message_id: messageId,
102
+ outcome: "failed"
85
103
  };
86
104
  }
87
105
  };
@@ -127,111 +145,4 @@ AmqpController.publishPendingMessageInCache = async () => {
127
145
  };
128
146
  }
129
147
  };
130
-
131
- /**
132
- * Publishes a message to the specified exchange with a given routing key and priority (pushes to central rabbitmq).
133
- *
134
- * This function interacts with the CentralRabbitMQHelper instance to send messages
135
- * to a message broker (e.g., RabbitMQ). It returns a structured response indicating
136
- * whether the message was successfully published or if an error occurred.
137
- *
138
- * @param {string} exchange - The name of the exchange to publish the message to.
139
- * @param {string} routingKey - The routing key used for message routing.
140
- * @param {Object|string} message - The message payload to be published. Can be an object or a string.
141
- * @param {number} [priority=1] - (Optional) The priority level of the message. Defaults to 1.
142
- *
143
- * @returns {Promise<Object>} - A promise that resolves to an object containing:
144
- * - `success` (boolean): Indicates if the message was successfully published.
145
- * - `message` (string): A descriptive message about the operation's outcome.
146
- * - `data` (any): Additional data related to the operation or error details if the operation failed.
147
- *
148
- */
149
- AmqpController.publishCentralMQMessage = async (exchange, routingKey, message, priority = 1) => {
150
- if (process.env.DISABLE_CENTRAL_RABBITMQ) {
151
- return {
152
- success: false,
153
- message: "CENTRAL_RABBITMQ is disabled.",
154
- data: null
155
- };
156
- }
157
- let publishMessage = message;
158
- if (!mbConfigs.centralRabbitmqUrl) {
159
- await DeadQueueService.storeFailureMessage({
160
- exchange,
161
- routingKey,
162
- message,
163
- priority,
164
- failureMessage: "No central rabbitmq url found."
165
- }, "central_deadqueue", "Central-MQ");
166
- return {
167
- success: false,
168
- message: "CENTRAL_RABBITMQ_URL is required for central message brokers initialization.",
169
- data: null
170
- };
171
- }
172
- const rawMessage = JSON.parse(JSON.stringify(message));
173
- const result = await maskPid(rawMessage, routingKey);
174
- if (result.success) {
175
- publishMessage = result.message;
176
- } else {
177
- await DeadQueueService.storeFailureMessage({
178
- exchange,
179
- routingKey,
180
- message,
181
- priority,
182
- failureMessage: "Error while masking pid.",
183
- errorObject: result.error
184
- }, "central_deadqueue_masking", "Central-MQ");
185
- return {
186
- success: false,
187
- message: "Error while masking pid.",
188
- data: error
189
- };
190
- }
191
- try {
192
- const {
193
- error,
194
- message: msg,
195
- data
196
- } = await CentralRabbitMQHelper.publish(exchange, routingKey, publishMessage, priority);
197
- if (!error) {
198
- console.log(`INFO: [${new Date().toLocaleString()}] [Central-MQ]: ${routingKey} successfully published into the exchange.`);
199
- return {
200
- success: true,
201
- message: msg,
202
- data
203
- };
204
- } else {
205
- console.log(`ERROR: [${new Date().toLocaleString()}] [Central-MQ]: Error while publishing ${routingKey} into the exchange.`);
206
- await DeadQueueService.storeFailureMessage({
207
- exchange,
208
- routingKey,
209
- message: publishMessage,
210
- priority,
211
- failureMessage: "Error while publishing into central rabbitmq.",
212
- errorObject: error
213
- }, "central_deadqueue", "Central-MQ");
214
- return {
215
- success: false,
216
- message: msg,
217
- data: `${error}`
218
- };
219
- }
220
- } catch (error) {
221
- console.log(`ERROR: [${new Date().toLocaleString()}] [Central-MQ]: Error while publishing ${routingKey} into the exchange.`);
222
- await DeadQueueService.storeFailureMessage({
223
- exchange,
224
- routingKey,
225
- message,
226
- priority,
227
- failureMessage: "Unexpected error while publishing into central rabbitmq.",
228
- errorObject: error
229
- }, "central_deadqueue", "Central-MQ");
230
- return {
231
- success: false,
232
- message: `Error publishing into central rabbitmq for ${routingKey}`,
233
- data: error
234
- };
235
- }
236
- };
237
148
  module.exports = AmqpController;
@@ -1,4 +1,7 @@
1
- require("dotenv").config();
1
+ // quiet: dotenv 17+ otherwise logs "injected env (n) from .env" in every app that loads the package
2
+ require("dotenv").config({
3
+ quiet: true
4
+ });
2
5
  const package_loader = require("./package-loader");
3
6
  const AmqpController = require("./controllers/amqp.controller");
4
7
  const mbConfigs = require("./configs/mb.configs");
@@ -6,18 +9,12 @@ const {
6
9
  setActiveApplication
7
10
  } = require("./helpers/app.helper");
8
11
  const hv_exchange = "hv.exchange";
9
- const central_hv_exchange = "central.hv.exchange";
10
12
  class MessageBrokers {
11
13
  constructor(mongoConnectionHolder, applicationName) {
12
14
  this.mongoConnectionHolder = mongoConnectionHolder;
13
15
  this.applicationName = applicationName || "mb_app";
14
16
  this._initialized = false;
15
17
  }
16
-
17
- /**
18
- * Initializes the AMQP connection and MongoDB connection.
19
- * @returns A promise that resolves to a response object.
20
- */
21
18
  async init() {
22
19
  if (this._initialized) return;
23
20
  try {
@@ -35,147 +32,180 @@ class MessageBrokers {
35
32
  /**
36
33
  * This function is used publish har into the exchange.
37
34
  * @param {Object} har
35
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
38
36
  * @returns
39
37
  */
40
- async publishHar(har) {
41
- const response = await AmqpController.publishMessage(hv_exchange, "har", har);
38
+ async publishHar(har, options = {}) {
39
+ const response = await AmqpController.publishMessage(hv_exchange, "har", har, undefined, options);
42
40
  return response;
43
41
  }
44
42
 
45
43
  /**
46
44
  * This function is used publish har_meta into the exchange.
47
45
  * @param {Object} har_meta
46
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
48
47
  * @returns
49
48
  */
50
- async publishHarMeta(har_meta) {
51
- const response = await AmqpController.publishMessage(hv_exchange, "har_meta", har_meta);
49
+ async publishHarMeta(har_meta, options = {}) {
50
+ const response = await AmqpController.publishMessage(hv_exchange, "har_meta", har_meta, undefined, options);
52
51
  return response;
53
52
  }
54
53
 
55
54
  /**
56
55
  * This function is used publish lab_api_response into the exchange.
57
56
  * @param {Object} lab_api_response
57
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
58
58
  * @returns
59
59
  */
60
- async publishLabApiResponse(lab_api_response) {
61
- const response = await AmqpController.publishMessage(hv_exchange, "lab_api_response", lab_api_response, 2);
60
+ async publishLabApiResponse(lab_api_response, options = {}) {
61
+ const response = await AmqpController.publishMessage(hv_exchange, "lab_api_response", lab_api_response, 2, options);
62
62
  return response;
63
63
  }
64
64
 
65
65
  /**
66
66
  * This function is used publish harLab_api_response into the exchange.
67
67
  * @param {Object} harLab_api_response
68
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
68
69
  * @returns
69
70
  */
70
- async publishHarLabApiResponse(harLab_api_response) {
71
- const response = await AmqpController.publishMessage(hv_exchange, "har.lab_api_response", harLab_api_response);
71
+ async publishHarLabApiResponse(harLab_api_response, options = {}) {
72
+ const response = await AmqpController.publishMessage(hv_exchange, "har.lab_api_response", harLab_api_response, undefined, options);
72
73
  return response;
73
74
  }
74
75
 
75
76
  /**
76
77
  * This function is used publish purchase_details into the exchange.
77
78
  * @param {Object} purchase_details
79
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
78
80
  * @returns
79
81
  */
80
- async publishPurchaseDetails(purchase_details) {
81
- const response = await AmqpController.publishMessage(hv_exchange, "purchase_details", purchase_details);
82
+ async publishPurchaseDetails(purchase_details, options = {}) {
83
+ const response = await AmqpController.publishMessage(hv_exchange, "purchase_details", purchase_details, undefined, options);
82
84
  return response;
83
85
  }
84
86
 
85
87
  /**
86
88
  * This function is used publish lab_location_data into the exchange.
87
89
  * @param {Object} lab_location_data
90
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
88
91
  * @returns
89
92
  */
90
- async publishLabLocationData(lab_location_data) {
91
- const response = await AmqpController.publishMessage(hv_exchange, "lab_location_data", lab_location_data);
93
+ async publishLabLocationData(lab_location_data, options = {}) {
94
+ const response = await AmqpController.publishMessage(hv_exchange, "lab_location_data", lab_location_data, undefined, options);
92
95
  return response;
93
96
  }
94
97
 
95
98
  /**
96
99
  * This function is used publish input_object into the exchange.
97
100
  * @param {Object} input_object
101
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
98
102
  * @returns
99
103
  */
100
- async publishInputObject(input_object) {
101
- const response = await AmqpController.publishMessage(hv_exchange, "input_object", input_object);
104
+ async publishInputObject(input_object, options = {}) {
105
+ const response = await AmqpController.publishMessage(hv_exchange, "input_object", input_object, undefined, options);
102
106
  return response;
103
107
  }
104
108
 
105
109
  /**
106
110
  * This function is used publish har_stub into the exchange.
107
111
  * @param {Object} har_stub
112
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
108
113
  * @returns
109
114
  */
110
- async publishHarStub(har_stub) {
111
- const response = await AmqpController.publishMessage(hv_exchange, "har_stub", har_stub);
115
+ async publishHarStub(har_stub, options = {}) {
116
+ const response = await AmqpController.publishMessage(hv_exchange, "har_stub", har_stub, undefined, options);
112
117
  return response;
113
118
  }
114
119
 
115
120
  /**
116
121
  * This function is used publish trending_data into the exchange.
117
122
  * @param {Object} trending_data
123
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
118
124
  * @returns
119
125
  */
120
- async publishTrendingData(trending_data) {
121
- const response = await AmqpController.publishMessage(hv_exchange, "trending_data", trending_data);
126
+ async publishTrendingData(trending_data, options = {}) {
127
+ const response = await AmqpController.publishMessage(hv_exchange, "trending_data", trending_data, undefined, options);
122
128
  return response;
123
129
  }
124
130
 
125
131
  /**
126
132
  * This function is used publish raw_queue into the exchange.
127
133
  * @param {Object} raw_queue
134
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
128
135
  * @returns
129
136
  */
130
- async publishRawQueue(raw_queue) {
131
- const response = await AmqpController.publishMessage(hv_exchange, "raw_queue", raw_queue);
137
+ async publishRawQueue(raw_queue, options = {}) {
138
+ const response = await AmqpController.publishMessage(hv_exchange, "raw_queue", raw_queue, undefined, options);
132
139
  return response;
133
140
  }
134
141
 
135
142
  /**
136
143
  * This function is used publish notification_messages_logs into the exchange.
137
144
  * @param {Object} notification_messages_logs
145
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
138
146
  * @returns
139
147
  */
140
- async publishNotificationMessagesLogs(notification_messages_logs) {
141
- const response = await AmqpController.publishMessage(hv_exchange, "notification_messages_logs", notification_messages_logs);
148
+ async publishNotificationMessagesLogs(notification_messages_logs, options = {}) {
149
+ const response = await AmqpController.publishMessage(hv_exchange, "notification_messages_logs", notification_messages_logs, undefined, options);
142
150
  return response;
143
151
  }
144
152
 
145
153
  /**
146
154
  * This function is used publish amqp_lab_api_response into the exchange.
147
155
  * @param {Object} amqp_lab_api_response
156
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
157
+ * @returns
158
+ */
159
+ async publishAmqpLabApiResponse(amqp_lab_api_response, options = {}) {
160
+ const response = await AmqpController.publishMessage(hv_exchange, "lab_api_response.amqp", amqp_lab_api_response, undefined, options);
161
+ return response;
162
+ }
163
+
164
+ /**
165
+ * This function is used publish merged_lab_api_response into the exchange.
166
+ * @param {Object} merged_lab_api_response
167
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
148
168
  * @returns
149
169
  */
150
- async publishAmqpLabApiResponse(amqp_lab_api_response) {
151
- const response = await AmqpController.publishMessage(hv_exchange, "lab_api_response.amqp", amqp_lab_api_response);
170
+ async publishAmqpMergedLabApiResponse(merged_lab_api_response, options = {}) {
171
+ const response = await AmqpController.publishMessage(hv_exchange, "merged_lab_api_response.amqp", merged_lab_api_response, undefined, options);
152
172
  return response;
153
173
  }
154
174
 
155
175
  /**
156
176
  * This function is used publish billing events into the exchange.
157
177
  * @param {Object} amqp_lab_api_response
178
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
158
179
  * @returns
159
180
  */
160
- async publishBillingEvents(billing_events) {
161
- const response = await AmqpController.publishMessage(hv_exchange, "billing", billing_events);
181
+ async publishBillingEvents(billing_events, options = {}) {
182
+ const response = await AmqpController.publishMessage(hv_exchange, "billing", billing_events, undefined, options);
162
183
  return response;
163
184
  }
164
185
 
165
186
  /**
166
- * This function is used publish purchase_details into the central exchange.
167
- * @param {Object} purchase_details
187
+ * This function is used publish a past data reminder request into the exchange.
188
+ * Consumed by the LLM reminder app (llm-reminder.past-data.queue).
189
+ * @param {Object} reminder_request
190
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
168
191
  * @returns
169
192
  */
170
- async publishCentralPurchaseDetails(purchase_details) {
171
- const response = await AmqpController.publishCentralMQMessage(central_hv_exchange, "purchase_details", purchase_details);
193
+ async publishPastDataReminderRequest(reminder_request, options = {}) {
194
+ const response = await AmqpController.publishMessage(hv_exchange, "past_data.reminder_request", reminder_request, undefined, options);
172
195
  return response;
173
196
  }
174
197
 
175
198
  /**
176
- * This function is used publish pending messages from cache into the exchange.
199
+ * This function is used publish a prepared past data reminder message into the exchange.
200
+ * Consumed by hv-connect (messaging.past-data.reminder-message.queue).
201
+ * @param {Object} reminder_message
202
+ * @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
177
203
  * @returns
178
204
  */
205
+ async publishPastDataReminderMessage(reminder_message, options = {}) {
206
+ const response = await AmqpController.publishMessage(hv_exchange, "past_data.reminder_message", reminder_message, undefined, options);
207
+ return response;
208
+ }
179
209
  async publishPendingMessageInCache() {
180
210
  return await AmqpController.publishPendingMessageInCache();
181
211
  }
@@ -4,8 +4,6 @@ const {
4
4
  const redisDB = require("./helpers/redis.helper");
5
5
  const mongoDB = require("./helpers/mongodb.helper");
6
6
  const MessageBroker = require("./helpers/message-brokers.helper");
7
- const CentralRabbitMQHelper = require("./rabbitmq/centralRabbitmq/centralRabbitmq.helper");
8
- const mbConfigs = require("./configs/mb.configs");
9
7
 
10
8
  /**
11
9
  * This function is used to load all the db connections,
@@ -19,15 +17,6 @@ const package_loader = async (mongoConnectionHolder, rabbitMqEnable = true) => {
19
17
  await MessageBroker.connect();
20
18
  await MessageBroker.initializePubSub();
21
19
  }
22
- if (!process.env.DISABLE_CENTRAL_RABBITMQ) {
23
- if (!mbConfigs.centralRabbitmqUrl) {
24
- throw new Error(`[central-amqp] CENTRAL_RABBITMQ_URL is not set for central RabbitMQ initialization!`);
25
- }
26
- await CentralRabbitMQHelper.connect();
27
- await CentralRabbitMQHelper.initializePubSub();
28
- } else {
29
- console.log("[central-amqp] Central RabbitMQ is disabled!");
30
- }
31
20
  if (mongoConnectionHolder.connection) {
32
21
  await mongoDB(mongoConnectionHolder.connection);
33
22
  }