message-brokers 1.11.0-beta.3 → 1.11.0-beta.5
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 +16 -2
- package/lib/configs/mb.configs.js +4 -3
- package/lib/configs/mqConfigs.js +13 -7
- package/lib/message-brokers.js +29 -2
- package/lib/types/message-brokers.d.ts +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -192,6 +192,12 @@ messageBrokers.publishPastDataReminderRequest(reminder_request);
|
|
|
192
192
|
|
|
193
193
|
// Publish prepared past data reminder message (LLM reminder app → hv-connect)
|
|
194
194
|
messageBrokers.publishPastDataReminderMessage(reminder_message);
|
|
195
|
+
|
|
196
|
+
// Publish live data reminder request (hvconnect → LLM reminder app)
|
|
197
|
+
messageBrokers.publishLiveReminderRequest(reminder_request);
|
|
198
|
+
|
|
199
|
+
// Publish prepared live data reminder message (LLM reminder app → hv-connect)
|
|
200
|
+
messageBrokers.publishLiveReminderMessage(reminder_message);
|
|
195
201
|
```
|
|
196
202
|
|
|
197
203
|
## RabbitMQ Utils Usage
|
|
@@ -244,11 +250,19 @@ An isolated queue must be on **both** lists, otherwise the publish key and the b
|
|
|
244
250
|
| `v2.lab-data.queue` | yes |
|
|
245
251
|
| `v2.merged-lab-data.queue` | yes |
|
|
246
252
|
| `billing.events` | yes |
|
|
247
|
-
| `
|
|
248
|
-
| `
|
|
253
|
+
| `carecue.request.queue` | yes |
|
|
254
|
+
| `carecue.response.queue` | yes |
|
|
249
255
|
|
|
250
256
|
When you add a queue, decide whether its data may cross servers or must stay on one. Changing the isolation of an existing queue renames it on deployments that set `RABBITMQ_ISOLATED_NAMESPACE`. Upgrade the publisher and the consumers together, then drain and delete the old queue, because the package doesn't remove it.
|
|
251
257
|
|
|
258
|
+
## Priority queues
|
|
259
|
+
|
|
260
|
+
`carecue.request.queue` and `carecue.response.queue` are priority queues (`x-max-priority: 2`, since 1.11.0-beta.5). Live messages (`live.reminder_request`, `live.reminder_message`) are published with priority 2, past data with the default priority 1, so live messages are delivered first when the queue has a backlog.
|
|
261
|
+
|
|
262
|
+
- **Consumers** that declare these queues must use the same arguments (`{ durable: true, arguments: { "x-max-priority": 2 } }`) or use `checkQueue`. A declaration with different arguments fails with `PRECONDITION_FAILED` and closes the channel.
|
|
263
|
+
- **Set a prefetch** (for example `channel.prefetch(5)`) on the consumer. Without one, RabbitMQ pushes every message to the consumer straight away and the priority has no effect.
|
|
264
|
+
- **An existing queue can't become a priority queue.** Drain and delete the old queue by hand before deploying, then let `init()` declare it again.
|
|
265
|
+
|
|
252
266
|
## Publish options
|
|
253
267
|
|
|
254
268
|
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`.
|
|
@@ -5,9 +5,10 @@ const mbConfigs = {
|
|
|
5
5
|
cachingEnabled: process.env.CACHING_ENABLED || false,
|
|
6
6
|
// Queues that are used in env where multiple instances of same stack share the same rabbitmq.
|
|
7
7
|
// To avoid messages between different instances, we are isolating the queues.
|
|
8
|
-
rabbitmqIsolatedQueues: ["messaging.har.lab-api.queue", "billing.events", "
|
|
9
|
-
// Matched by prefix: "past_data." covers past_data.reminder_request and past_data.reminder_message
|
|
8
|
+
rabbitmqIsolatedQueues: ["messaging.har.lab-api.queue", "billing.events", "carecue.request.queue", "carecue.response.queue", "v2.lab-data.queue", "v2.merged-lab-data.queue"],
|
|
9
|
+
// Matched by prefix: "past_data." covers past_data.reminder_request and past_data.reminder_message,
|
|
10
|
+
// "live." covers live.reminder_request and live.reminder_message.
|
|
10
11
|
// The lab-data keys are listed in full so the plain "lab_api_response" key (datacloak.queue) stays shared.
|
|
11
|
-
rabbitmqIsolatedRoutingKeys: ["har.lab_api_response", "billing", "past_data.", "lab_api_response.amqp", "merged_lab_api_response.amqp"]
|
|
12
|
+
rabbitmqIsolatedRoutingKeys: ["har.lab_api_response", "billing", "past_data.", "live.", "lab_api_response.amqp", "merged_lab_api_response.amqp"]
|
|
12
13
|
};
|
|
13
14
|
module.exports = mbConfigs;
|
package/lib/configs/mqConfigs.js
CHANGED
|
@@ -29,13 +29,19 @@ const mqConfigs = [{
|
|
|
29
29
|
routingKeyList: ["billing"],
|
|
30
30
|
priorityQueue: false
|
|
31
31
|
}, {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
// Requests to CareCue (the LLM reminder app), one routing key per flow
|
|
33
|
+
queueName: "carecue.request.queue",
|
|
34
|
+
routingKeyList: ["past_data.reminder_request", "live.reminder_request"],
|
|
35
|
+
// Priority queue: live messages (priority 2) are delivered before past data (priority 1)
|
|
36
|
+
priorityQueue: true,
|
|
37
|
+
maxPriority: 2
|
|
38
|
+
}, {
|
|
39
|
+
// CareCue's replies, one routing key per flow
|
|
40
|
+
queueName: "carecue.response.queue",
|
|
41
|
+
routingKeyList: ["past_data.reminder_message", "live.reminder_message"],
|
|
42
|
+
// Priority queue: live messages (priority 2) are delivered before past data (priority 1)
|
|
43
|
+
priorityQueue: true,
|
|
44
|
+
maxPriority: 2
|
|
39
45
|
}
|
|
40
46
|
// Example for priority queue.
|
|
41
47
|
// {
|
package/lib/message-brokers.js
CHANGED
|
@@ -9,6 +9,9 @@ const {
|
|
|
9
9
|
setActiveApplication
|
|
10
10
|
} = require("./helpers/app.helper");
|
|
11
11
|
const hv_exchange = "hv.exchange";
|
|
12
|
+
// carecue.request.queue and carecue.response.queue are priority queues (x-max-priority 2).
|
|
13
|
+
// Live reminders go out at priority 2; past data uses the default priority 1.
|
|
14
|
+
const LIVE_REMINDER_PRIORITY = 2;
|
|
12
15
|
class MessageBrokers {
|
|
13
16
|
constructor(mongoConnectionHolder, applicationName) {
|
|
14
17
|
this.mongoConnectionHolder = mongoConnectionHolder;
|
|
@@ -185,7 +188,7 @@ class MessageBrokers {
|
|
|
185
188
|
|
|
186
189
|
/**
|
|
187
190
|
* This function is used publish a past data reminder request into the exchange.
|
|
188
|
-
* Consumed by the LLM reminder app (
|
|
191
|
+
* Consumed by the LLM reminder app (carecue.request.queue).
|
|
189
192
|
* @param {Object} reminder_request
|
|
190
193
|
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
191
194
|
* @returns
|
|
@@ -197,7 +200,7 @@ class MessageBrokers {
|
|
|
197
200
|
|
|
198
201
|
/**
|
|
199
202
|
* This function is used publish a prepared past data reminder message into the exchange.
|
|
200
|
-
* Consumed by hv-connect (
|
|
203
|
+
* Consumed by hv-connect (carecue.response.queue).
|
|
201
204
|
* @param {Object} reminder_message
|
|
202
205
|
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
203
206
|
* @returns
|
|
@@ -206,6 +209,30 @@ class MessageBrokers {
|
|
|
206
209
|
const response = await AmqpController.publishMessage(hv_exchange, "past_data.reminder_message", reminder_message, undefined, options);
|
|
207
210
|
return response;
|
|
208
211
|
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* This function is used publish a live data reminder request into the exchange.
|
|
215
|
+
* Consumed by the LLM reminder app (carecue.request.queue).
|
|
216
|
+
* @param {Object} reminder_request
|
|
217
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
218
|
+
* @returns
|
|
219
|
+
*/
|
|
220
|
+
async publishLiveReminderRequest(reminder_request, options = {}) {
|
|
221
|
+
const response = await AmqpController.publishMessage(hv_exchange, "live.reminder_request", reminder_request, LIVE_REMINDER_PRIORITY, options);
|
|
222
|
+
return response;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* This function is used publish a prepared live data reminder message into the exchange.
|
|
227
|
+
* Consumed by hv-connect (carecue.response.queue).
|
|
228
|
+
* @param {Object} reminder_message
|
|
229
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
230
|
+
* @returns
|
|
231
|
+
*/
|
|
232
|
+
async publishLiveReminderMessage(reminder_message, options = {}) {
|
|
233
|
+
const response = await AmqpController.publishMessage(hv_exchange, "live.reminder_message", reminder_message, LIVE_REMINDER_PRIORITY, options);
|
|
234
|
+
return response;
|
|
235
|
+
}
|
|
209
236
|
async publishPendingMessageInCache() {
|
|
210
237
|
return await AmqpController.publishPendingMessageInCache();
|
|
211
238
|
}
|
|
@@ -176,6 +176,22 @@ declare module "message-brokers" {
|
|
|
176
176
|
*/
|
|
177
177
|
publishPastDataReminderMessage(reminder_message: object, options?: PublishOptions): Promise<PublishResponse>;
|
|
178
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Publishes a live data reminder request into the exchange (routing key live.reminder_request).
|
|
181
|
+
* @param reminder_request - The reminder request object to be published.
|
|
182
|
+
* @param options - Optional publish options (messageId, retry, waitForConfirm, confirmTimeoutMs).
|
|
183
|
+
* @returns A promise that resolves to a response object.
|
|
184
|
+
*/
|
|
185
|
+
publishLiveReminderRequest(reminder_request: object, options?: PublishOptions): Promise<PublishResponse>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Publishes a prepared live data reminder message into the exchange (routing key live.reminder_message).
|
|
189
|
+
* @param reminder_message - The reminder message object to be published.
|
|
190
|
+
* @param options - Optional publish options (messageId, retry, waitForConfirm, confirmTimeoutMs).
|
|
191
|
+
* @returns A promise that resolves to a response object.
|
|
192
|
+
*/
|
|
193
|
+
publishLiveReminderMessage(reminder_message: object, options?: PublishOptions): Promise<PublishResponse>;
|
|
194
|
+
|
|
179
195
|
/**
|
|
180
196
|
* Publishes a raw queue object into the exchange.
|
|
181
197
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "message-brokers",
|
|
3
|
-
"version": "1.11.0-beta.
|
|
3
|
+
"version": "1.11.0-beta.5",
|
|
4
4
|
"description": "This package contains functions to publish the messages into the message brokers like rabbitmq.",
|
|
5
5
|
"main": "lib/message-brokers.js",
|
|
6
6
|
"types": "lib/types/message-brokers.d.ts",
|