message-brokers 1.11.0-beta.2 → 1.11.0-beta.4
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 +36 -1
- package/lib/configs/mb.configs.js +5 -3
- package/lib/configs/mqConfigs.js +6 -4
- package/lib/message-brokers.js +26 -2
- package/lib/types/message-brokers.d.ts +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ RABBITMQ_DEPLOYMENT_ENV=stage
|
|
|
55
55
|
#
|
|
56
56
|
# Example:
|
|
57
57
|
# base.queue → base.queue.stage
|
|
58
|
-
# base-key → base-key
|
|
58
|
+
# base-key → base-key-stage
|
|
59
59
|
#
|
|
60
60
|
# Use this when multiple environments (stage/dev/prod) share the same RabbitMQ cluster.
|
|
61
61
|
|
|
@@ -74,6 +74,7 @@ RABBITMQ_ISOLATED_NAMESPACE=prod-2
|
|
|
74
74
|
#
|
|
75
75
|
# Example:
|
|
76
76
|
# messaging.queue → messaging.queue.prod-2
|
|
77
|
+
# messaging-key → messaging-key-prod-2
|
|
77
78
|
#
|
|
78
79
|
# Purpose:
|
|
79
80
|
# - Enables tenant-level or client-level isolation within the same broker
|
|
@@ -191,6 +192,12 @@ messageBrokers.publishPastDataReminderRequest(reminder_request);
|
|
|
191
192
|
|
|
192
193
|
// Publish prepared past data reminder message (LLM reminder app → hv-connect)
|
|
193
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);
|
|
194
201
|
```
|
|
195
202
|
|
|
196
203
|
## RabbitMQ Utils Usage
|
|
@@ -220,6 +227,34 @@ The example output assumes `RABBITMQ_ISOLATED_NAMESPACE=prod-2` and `RABBITMQ_DE
|
|
|
220
227
|
|
|
221
228
|
The package's `exports` allow only `message-brokers`, `message-brokers/rabbitmq-utils`, `message-brokers/lib/*` and `message-brokers/package.json` to be imported.
|
|
222
229
|
|
|
230
|
+
## Queue isolation
|
|
231
|
+
|
|
232
|
+
Some deployments run two or more servers (stacks) against the same RabbitMQ with the same `RABBITMQ_DEPLOYMENT_ENV`. Each server then sets its own `RABBITMQ_ISOLATED_NAMESPACE` (e.g. `prod-1`, `prod-2`).
|
|
233
|
+
|
|
234
|
+
- **Shared queue (not isolated):** every server binds the same queue and routing key, so a message published by one server can be consumed by any of them. The data flows across servers.
|
|
235
|
+
- **Isolated queue:** each server gets its own queue (`<queue>.<ns>.<env>`) and routing key (`<key>-<ns>-<env>`), so a message stays on the server that published it.
|
|
236
|
+
|
|
237
|
+
Isolation is decided per queue, because one deployment usually needs both kinds. It's configured in `src/configs/mb.configs.js`:
|
|
238
|
+
|
|
239
|
+
- `rabbitmqIsolatedQueues`: queue names. Bindings use these to get the namespace.
|
|
240
|
+
- `rabbitmqIsolatedRoutingKeys`: routing keys. Publishing uses these to get the namespace.
|
|
241
|
+
|
|
242
|
+
An isolated queue must be on **both** lists, otherwise the publish key and the binding key differ and messages are dropped. Both lists are matched by prefix.
|
|
243
|
+
|
|
244
|
+
| Queue | Isolated |
|
|
245
|
+
|---|---|
|
|
246
|
+
| `data-flattening.har.queue` | no |
|
|
247
|
+
| `messaging.har.lab-api.queue` | yes |
|
|
248
|
+
| `datacloak.queue` | no |
|
|
249
|
+
| `raw-queue-processor` | no |
|
|
250
|
+
| `v2.lab-data.queue` | yes |
|
|
251
|
+
| `v2.merged-lab-data.queue` | yes |
|
|
252
|
+
| `billing.events` | yes |
|
|
253
|
+
| `carecue.request.queue` | yes |
|
|
254
|
+
| `carecue.response.queue` | yes |
|
|
255
|
+
|
|
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.
|
|
257
|
+
|
|
223
258
|
## Publish options
|
|
224
259
|
|
|
225
260
|
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,8 +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
|
|
10
|
-
|
|
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.
|
|
11
|
+
// The lab-data keys are listed in full so the plain "lab_api_response" key (datacloak.queue) stays shared.
|
|
12
|
+
rabbitmqIsolatedRoutingKeys: ["har.lab_api_response", "billing", "past_data.", "live.", "lab_api_response.amqp", "merged_lab_api_response.amqp"]
|
|
11
13
|
};
|
|
12
14
|
module.exports = mbConfigs;
|
package/lib/configs/mqConfigs.js
CHANGED
|
@@ -29,12 +29,14 @@ const mqConfigs = [{
|
|
|
29
29
|
routingKeyList: ["billing"],
|
|
30
30
|
priorityQueue: false
|
|
31
31
|
}, {
|
|
32
|
-
|
|
33
|
-
|
|
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"],
|
|
34
35
|
priorityQueue: false
|
|
35
36
|
}, {
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
// CareCue's replies, one routing key per flow
|
|
38
|
+
queueName: "carecue.response.queue",
|
|
39
|
+
routingKeyList: ["past_data.reminder_message", "live.reminder_message"],
|
|
38
40
|
priorityQueue: false
|
|
39
41
|
}
|
|
40
42
|
// Example for priority queue.
|
package/lib/message-brokers.js
CHANGED
|
@@ -185,7 +185,7 @@ class MessageBrokers {
|
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
187
|
* This function is used publish a past data reminder request into the exchange.
|
|
188
|
-
* Consumed by the LLM reminder app (
|
|
188
|
+
* Consumed by the LLM reminder app (carecue.request.queue).
|
|
189
189
|
* @param {Object} reminder_request
|
|
190
190
|
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
191
191
|
* @returns
|
|
@@ -197,7 +197,7 @@ class MessageBrokers {
|
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
199
|
* This function is used publish a prepared past data reminder message into the exchange.
|
|
200
|
-
* Consumed by hv-connect (
|
|
200
|
+
* Consumed by hv-connect (carecue.response.queue).
|
|
201
201
|
* @param {Object} reminder_message
|
|
202
202
|
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
203
203
|
* @returns
|
|
@@ -206,6 +206,30 @@ class MessageBrokers {
|
|
|
206
206
|
const response = await AmqpController.publishMessage(hv_exchange, "past_data.reminder_message", reminder_message, undefined, options);
|
|
207
207
|
return response;
|
|
208
208
|
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* This function is used publish a live data reminder request into the exchange.
|
|
212
|
+
* Consumed by the LLM reminder app (carecue.request.queue).
|
|
213
|
+
* @param {Object} reminder_request
|
|
214
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
215
|
+
* @returns
|
|
216
|
+
*/
|
|
217
|
+
async publishLiveReminderRequest(reminder_request, options = {}) {
|
|
218
|
+
const response = await AmqpController.publishMessage(hv_exchange, "live.reminder_request", reminder_request, undefined, options);
|
|
219
|
+
return response;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* This function is used publish a prepared live data reminder message into the exchange.
|
|
224
|
+
* Consumed by hv-connect (carecue.response.queue).
|
|
225
|
+
* @param {Object} reminder_message
|
|
226
|
+
* @param {PublishOptions} [options] Optional: messageId, retry, waitForConfirm, confirmTimeoutMs (see README "Publish options").
|
|
227
|
+
* @returns
|
|
228
|
+
*/
|
|
229
|
+
async publishLiveReminderMessage(reminder_message, options = {}) {
|
|
230
|
+
const response = await AmqpController.publishMessage(hv_exchange, "live.reminder_message", reminder_message, undefined, options);
|
|
231
|
+
return response;
|
|
232
|
+
}
|
|
209
233
|
async publishPendingMessageInCache() {
|
|
210
234
|
return await AmqpController.publishPendingMessageInCache();
|
|
211
235
|
}
|
|
@@ -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.4",
|
|
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",
|