message-brokers 1.11.0-beta.4 → 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 +8 -0
- package/lib/configs/mqConfigs.js +6 -2
- package/lib/message-brokers.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -255,6 +255,14 @@ An isolated queue must be on **both** lists, otherwise the publish key and the b
|
|
|
255
255
|
|
|
256
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
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
|
+
|
|
258
266
|
## Publish options
|
|
259
267
|
|
|
260
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`.
|
package/lib/configs/mqConfigs.js
CHANGED
|
@@ -32,12 +32,16 @@ const mqConfigs = [{
|
|
|
32
32
|
// Requests to CareCue (the LLM reminder app), one routing key per flow
|
|
33
33
|
queueName: "carecue.request.queue",
|
|
34
34
|
routingKeyList: ["past_data.reminder_request", "live.reminder_request"],
|
|
35
|
-
|
|
35
|
+
// Priority queue: live messages (priority 2) are delivered before past data (priority 1)
|
|
36
|
+
priorityQueue: true,
|
|
37
|
+
maxPriority: 2
|
|
36
38
|
}, {
|
|
37
39
|
// CareCue's replies, one routing key per flow
|
|
38
40
|
queueName: "carecue.response.queue",
|
|
39
41
|
routingKeyList: ["past_data.reminder_message", "live.reminder_message"],
|
|
40
|
-
|
|
42
|
+
// Priority queue: live messages (priority 2) are delivered before past data (priority 1)
|
|
43
|
+
priorityQueue: true,
|
|
44
|
+
maxPriority: 2
|
|
41
45
|
}
|
|
42
46
|
// Example for priority queue.
|
|
43
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;
|
|
@@ -215,7 +218,7 @@ class MessageBrokers {
|
|
|
215
218
|
* @returns
|
|
216
219
|
*/
|
|
217
220
|
async publishLiveReminderRequest(reminder_request, options = {}) {
|
|
218
|
-
const response = await AmqpController.publishMessage(hv_exchange, "live.reminder_request", reminder_request,
|
|
221
|
+
const response = await AmqpController.publishMessage(hv_exchange, "live.reminder_request", reminder_request, LIVE_REMINDER_PRIORITY, options);
|
|
219
222
|
return response;
|
|
220
223
|
}
|
|
221
224
|
|
|
@@ -227,7 +230,7 @@ class MessageBrokers {
|
|
|
227
230
|
* @returns
|
|
228
231
|
*/
|
|
229
232
|
async publishLiveReminderMessage(reminder_message, options = {}) {
|
|
230
|
-
const response = await AmqpController.publishMessage(hv_exchange, "live.reminder_message", reminder_message,
|
|
233
|
+
const response = await AmqpController.publishMessage(hv_exchange, "live.reminder_message", reminder_message, LIVE_REMINDER_PRIORITY, options);
|
|
231
234
|
return response;
|
|
232
235
|
}
|
|
233
236
|
async publishPendingMessageInCache() {
|
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",
|