message-brokers 1.10.2-beta → 1.11.0-beta.0
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 +69 -0
- package/lib/configs/mb.configs.js +3 -3
- package/lib/configs/mqConfigs.js +12 -0
- package/lib/controllers/amqp.controller.js +53 -142
- package/lib/message-brokers.js +64 -37
- package/lib/package-loader.js +0 -11
- package/lib/rabbitmq/rabbitmq.helper.js +78 -14
- package/lib/services/deadqueue.service.js +121 -10
- package/lib/types/message-brokers.d.ts +213 -0
- package/lib/utils/log.util.js +6 -6
- package/package.json +7 -8
- package/lib/configs/centralMqConfigs.js +0 -17
- package/lib/helpers/centralRabbitmq/centralRabbitmq.helper.js +0 -156
- package/lib/helpers/centralRabbitmq/centralRabbitmqConnection.js +0 -38
- package/lib/rabbitmq/centralRabbitmq/centralRabbitmq.helper.js +0 -156
- package/lib/rabbitmq/centralRabbitmq/centralRabbitmqConnection.js +0 -38
- package/lib/types +0 -156
- package/lib/utils/maskPid.js +0 -147
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
|
-
|
|
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;
|
package/lib/configs/mqConfigs.js
CHANGED
|
@@ -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
|
-
*
|
|
13
|
-
*
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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;
|
package/lib/message-brokers.js
CHANGED
|
@@ -6,18 +6,12 @@ const {
|
|
|
6
6
|
setActiveApplication
|
|
7
7
|
} = require("./helpers/app.helper");
|
|
8
8
|
const hv_exchange = "hv.exchange";
|
|
9
|
-
const central_hv_exchange = "central.hv.exchange";
|
|
10
9
|
class MessageBrokers {
|
|
11
10
|
constructor(mongoConnectionHolder, applicationName) {
|
|
12
11
|
this.mongoConnectionHolder = mongoConnectionHolder;
|
|
13
12
|
this.applicationName = applicationName || "mb_app";
|
|
14
13
|
this._initialized = false;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Initializes the AMQP connection and MongoDB connection.
|
|
19
|
-
* @returns A promise that resolves to a response object.
|
|
20
|
-
*/
|
|
21
15
|
async init() {
|
|
22
16
|
if (this._initialized) return;
|
|
23
17
|
try {
|
|
@@ -35,147 +29,180 @@ class MessageBrokers {
|
|
|
35
29
|
/**
|
|
36
30
|
* This function is used publish har into the exchange.
|
|
37
31
|
* @param {Object} har
|
|
32
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
38
33
|
* @returns
|
|
39
34
|
*/
|
|
40
|
-
async publishHar(har) {
|
|
41
|
-
const response = await AmqpController.publishMessage(hv_exchange, "har", har);
|
|
35
|
+
async publishHar(har, options = {}) {
|
|
36
|
+
const response = await AmqpController.publishMessage(hv_exchange, "har", har, undefined, options);
|
|
42
37
|
return response;
|
|
43
38
|
}
|
|
44
39
|
|
|
45
40
|
/**
|
|
46
41
|
* This function is used publish har_meta into the exchange.
|
|
47
42
|
* @param {Object} har_meta
|
|
43
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
48
44
|
* @returns
|
|
49
45
|
*/
|
|
50
|
-
async publishHarMeta(har_meta) {
|
|
51
|
-
const response = await AmqpController.publishMessage(hv_exchange, "har_meta", har_meta);
|
|
46
|
+
async publishHarMeta(har_meta, options = {}) {
|
|
47
|
+
const response = await AmqpController.publishMessage(hv_exchange, "har_meta", har_meta, undefined, options);
|
|
52
48
|
return response;
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
/**
|
|
56
52
|
* This function is used publish lab_api_response into the exchange.
|
|
57
53
|
* @param {Object} lab_api_response
|
|
54
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
58
55
|
* @returns
|
|
59
56
|
*/
|
|
60
|
-
async publishLabApiResponse(lab_api_response) {
|
|
61
|
-
const response = await AmqpController.publishMessage(hv_exchange, "lab_api_response", lab_api_response, 2);
|
|
57
|
+
async publishLabApiResponse(lab_api_response, options = {}) {
|
|
58
|
+
const response = await AmqpController.publishMessage(hv_exchange, "lab_api_response", lab_api_response, 2, options);
|
|
62
59
|
return response;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
/**
|
|
66
63
|
* This function is used publish harLab_api_response into the exchange.
|
|
67
64
|
* @param {Object} harLab_api_response
|
|
65
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
68
66
|
* @returns
|
|
69
67
|
*/
|
|
70
|
-
async publishHarLabApiResponse(harLab_api_response) {
|
|
71
|
-
const response = await AmqpController.publishMessage(hv_exchange, "har.lab_api_response", harLab_api_response);
|
|
68
|
+
async publishHarLabApiResponse(harLab_api_response, options = {}) {
|
|
69
|
+
const response = await AmqpController.publishMessage(hv_exchange, "har.lab_api_response", harLab_api_response, undefined, options);
|
|
72
70
|
return response;
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
/**
|
|
76
74
|
* This function is used publish purchase_details into the exchange.
|
|
77
75
|
* @param {Object} purchase_details
|
|
76
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
78
77
|
* @returns
|
|
79
78
|
*/
|
|
80
|
-
async publishPurchaseDetails(purchase_details) {
|
|
81
|
-
const response = await AmqpController.publishMessage(hv_exchange, "purchase_details", purchase_details);
|
|
79
|
+
async publishPurchaseDetails(purchase_details, options = {}) {
|
|
80
|
+
const response = await AmqpController.publishMessage(hv_exchange, "purchase_details", purchase_details, undefined, options);
|
|
82
81
|
return response;
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
/**
|
|
86
85
|
* This function is used publish lab_location_data into the exchange.
|
|
87
86
|
* @param {Object} lab_location_data
|
|
87
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
88
88
|
* @returns
|
|
89
89
|
*/
|
|
90
|
-
async publishLabLocationData(lab_location_data) {
|
|
91
|
-
const response = await AmqpController.publishMessage(hv_exchange, "lab_location_data", lab_location_data);
|
|
90
|
+
async publishLabLocationData(lab_location_data, options = {}) {
|
|
91
|
+
const response = await AmqpController.publishMessage(hv_exchange, "lab_location_data", lab_location_data, undefined, options);
|
|
92
92
|
return response;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* This function is used publish input_object into the exchange.
|
|
97
97
|
* @param {Object} input_object
|
|
98
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
98
99
|
* @returns
|
|
99
100
|
*/
|
|
100
|
-
async publishInputObject(input_object) {
|
|
101
|
-
const response = await AmqpController.publishMessage(hv_exchange, "input_object", input_object);
|
|
101
|
+
async publishInputObject(input_object, options = {}) {
|
|
102
|
+
const response = await AmqpController.publishMessage(hv_exchange, "input_object", input_object, undefined, options);
|
|
102
103
|
return response;
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
/**
|
|
106
107
|
* This function is used publish har_stub into the exchange.
|
|
107
108
|
* @param {Object} har_stub
|
|
109
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
108
110
|
* @returns
|
|
109
111
|
*/
|
|
110
|
-
async publishHarStub(har_stub) {
|
|
111
|
-
const response = await AmqpController.publishMessage(hv_exchange, "har_stub", har_stub);
|
|
112
|
+
async publishHarStub(har_stub, options = {}) {
|
|
113
|
+
const response = await AmqpController.publishMessage(hv_exchange, "har_stub", har_stub, undefined, options);
|
|
112
114
|
return response;
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
/**
|
|
116
118
|
* This function is used publish trending_data into the exchange.
|
|
117
119
|
* @param {Object} trending_data
|
|
120
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
118
121
|
* @returns
|
|
119
122
|
*/
|
|
120
|
-
async publishTrendingData(trending_data) {
|
|
121
|
-
const response = await AmqpController.publishMessage(hv_exchange, "trending_data", trending_data);
|
|
123
|
+
async publishTrendingData(trending_data, options = {}) {
|
|
124
|
+
const response = await AmqpController.publishMessage(hv_exchange, "trending_data", trending_data, undefined, options);
|
|
122
125
|
return response;
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
/**
|
|
126
129
|
* This function is used publish raw_queue into the exchange.
|
|
127
130
|
* @param {Object} raw_queue
|
|
131
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
128
132
|
* @returns
|
|
129
133
|
*/
|
|
130
|
-
async publishRawQueue(raw_queue) {
|
|
131
|
-
const response = await AmqpController.publishMessage(hv_exchange, "raw_queue", raw_queue);
|
|
134
|
+
async publishRawQueue(raw_queue, options = {}) {
|
|
135
|
+
const response = await AmqpController.publishMessage(hv_exchange, "raw_queue", raw_queue, undefined, options);
|
|
132
136
|
return response;
|
|
133
137
|
}
|
|
134
138
|
|
|
135
139
|
/**
|
|
136
140
|
* This function is used publish notification_messages_logs into the exchange.
|
|
137
141
|
* @param {Object} notification_messages_logs
|
|
142
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
138
143
|
* @returns
|
|
139
144
|
*/
|
|
140
|
-
async publishNotificationMessagesLogs(notification_messages_logs) {
|
|
141
|
-
const response = await AmqpController.publishMessage(hv_exchange, "notification_messages_logs", notification_messages_logs);
|
|
145
|
+
async publishNotificationMessagesLogs(notification_messages_logs, options = {}) {
|
|
146
|
+
const response = await AmqpController.publishMessage(hv_exchange, "notification_messages_logs", notification_messages_logs, undefined, options);
|
|
142
147
|
return response;
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
/**
|
|
146
151
|
* This function is used publish amqp_lab_api_response into the exchange.
|
|
147
152
|
* @param {Object} amqp_lab_api_response
|
|
153
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
154
|
+
* @returns
|
|
155
|
+
*/
|
|
156
|
+
async publishAmqpLabApiResponse(amqp_lab_api_response, options = {}) {
|
|
157
|
+
const response = await AmqpController.publishMessage(hv_exchange, "lab_api_response.amqp", amqp_lab_api_response, undefined, options);
|
|
158
|
+
return response;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* This function is used publish merged_lab_api_response into the exchange.
|
|
163
|
+
* @param {Object} merged_lab_api_response
|
|
164
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
148
165
|
* @returns
|
|
149
166
|
*/
|
|
150
|
-
async
|
|
151
|
-
const response = await AmqpController.publishMessage(hv_exchange, "
|
|
167
|
+
async publishAmqpMergedLabApiResponse(merged_lab_api_response, options = {}) {
|
|
168
|
+
const response = await AmqpController.publishMessage(hv_exchange, "merged_lab_api_response.amqp", merged_lab_api_response, undefined, options);
|
|
152
169
|
return response;
|
|
153
170
|
}
|
|
154
171
|
|
|
155
172
|
/**
|
|
156
173
|
* This function is used publish billing events into the exchange.
|
|
157
174
|
* @param {Object} amqp_lab_api_response
|
|
175
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
158
176
|
* @returns
|
|
159
177
|
*/
|
|
160
|
-
async publishBillingEvents(billing_events) {
|
|
161
|
-
const response = await AmqpController.publishMessage(hv_exchange, "billing", billing_events);
|
|
178
|
+
async publishBillingEvents(billing_events, options = {}) {
|
|
179
|
+
const response = await AmqpController.publishMessage(hv_exchange, "billing", billing_events, undefined, options);
|
|
162
180
|
return response;
|
|
163
181
|
}
|
|
164
182
|
|
|
165
183
|
/**
|
|
166
|
-
* This function is used publish
|
|
167
|
-
*
|
|
184
|
+
* This function is used publish a past data reminder request into the exchange.
|
|
185
|
+
* Consumed by the LLM reminder app (llm-reminder.past-data.queue).
|
|
186
|
+
* @param {Object} reminder_request
|
|
187
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
168
188
|
* @returns
|
|
169
189
|
*/
|
|
170
|
-
async
|
|
171
|
-
const response = await AmqpController.
|
|
190
|
+
async publishPastDataReminderRequest(reminder_request, options = {}) {
|
|
191
|
+
const response = await AmqpController.publishMessage(hv_exchange, "past_data.reminder_request", reminder_request, undefined, options);
|
|
172
192
|
return response;
|
|
173
193
|
}
|
|
174
194
|
|
|
175
195
|
/**
|
|
176
|
-
* This function is used publish
|
|
196
|
+
* This function is used publish a prepared past data reminder message into the exchange.
|
|
197
|
+
* Consumed by hv-connect (messaging.past-data.reminder-message.queue).
|
|
198
|
+
* @param {Object} reminder_message
|
|
199
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
177
200
|
* @returns
|
|
178
201
|
*/
|
|
202
|
+
async publishPastDataReminderMessage(reminder_message, options = {}) {
|
|
203
|
+
const response = await AmqpController.publishMessage(hv_exchange, "past_data.reminder_message", reminder_message, undefined, options);
|
|
204
|
+
return response;
|
|
205
|
+
}
|
|
179
206
|
async publishPendingMessageInCache() {
|
|
180
207
|
return await AmqpController.publishPendingMessageInCache();
|
|
181
208
|
}
|
package/lib/package-loader.js
CHANGED
|
@@ -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
|
}
|