message-brokers 1.8.1 → 1.8.3
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 +5 -0
- package/lib/configs/mqConfigs.js +4 -0
- package/lib/message-brokers.js +20 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,6 +75,7 @@ db.on("error", (err) => {
|
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
const messageBrokers = new MessageBrokers(mongoConnectionHolder, "app_name");
|
|
78
|
+
await messageBrokers.init();
|
|
78
79
|
```
|
|
79
80
|
|
|
80
81
|
#### 2. Native Mongodb driver initialization
|
|
@@ -102,6 +103,7 @@ client
|
|
|
102
103
|
.catch((error) => console.error("❌ MongoDB connection failed:", error));
|
|
103
104
|
|
|
104
105
|
const messageBrokers = new MessageBrokers(mongoConnectionHolder, "app_name");
|
|
106
|
+
await messageBrokers.init();
|
|
105
107
|
```
|
|
106
108
|
|
|
107
109
|
## Usage
|
|
@@ -136,4 +138,7 @@ messageBrokers.publishNotificationMessagesLogs(notification_messages_logs);
|
|
|
136
138
|
|
|
137
139
|
// Publish amqp_lab_api_response
|
|
138
140
|
messageBrokers.publishAmqpLabApiResponse(amqp_lab_api_response);
|
|
141
|
+
|
|
142
|
+
// Publish billing_events
|
|
143
|
+
messageBrokers.publishBillingEvents(billing_events);
|
|
139
144
|
```
|
package/lib/configs/mqConfigs.js
CHANGED
|
@@ -20,6 +20,10 @@ const mqConfigs = [{
|
|
|
20
20
|
queueName: "v2.lab-data.queue",
|
|
21
21
|
routingKeyList: ["lab_api_response.amqp"],
|
|
22
22
|
priorityQueue: false
|
|
23
|
+
}, {
|
|
24
|
+
queueName: "billing.events",
|
|
25
|
+
routingKeyList: ["billing"],
|
|
26
|
+
priorityQueue: false
|
|
23
27
|
}
|
|
24
28
|
// Example for priority queue.
|
|
25
29
|
// {
|
package/lib/message-brokers.js
CHANGED
|
@@ -8,15 +8,22 @@ const {
|
|
|
8
8
|
const hv_exchange = "hv.exchange";
|
|
9
9
|
class MessageBrokers {
|
|
10
10
|
constructor(mongoConnectionHolder, applicationName) {
|
|
11
|
+
this.mongoConnectionHolder = mongoConnectionHolder;
|
|
12
|
+
this.applicationName = applicationName || "mb_app";
|
|
13
|
+
this._initialized = false;
|
|
14
|
+
}
|
|
15
|
+
async init() {
|
|
16
|
+
if (this._initialized) return;
|
|
11
17
|
try {
|
|
12
|
-
setActiveApplication(applicationName
|
|
18
|
+
setActiveApplication(this.applicationName);
|
|
13
19
|
if (!mbConfigs.rabbitmqUrl) {
|
|
14
20
|
throw new Error("RABBITMQ_URL is required for message brokers initialization.");
|
|
15
21
|
}
|
|
16
|
-
package_loader(mongoConnectionHolder, true);
|
|
22
|
+
await package_loader(this.mongoConnectionHolder, true);
|
|
17
23
|
} catch (error) {
|
|
18
|
-
package_loader(mongoConnectionHolder, false);
|
|
24
|
+
await package_loader(this.mongoConnectionHolder, false);
|
|
19
25
|
}
|
|
26
|
+
this._initialized = true;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
/**
|
|
@@ -138,6 +145,16 @@ class MessageBrokers {
|
|
|
138
145
|
const response = await AmqpController.publishMessage(hv_exchange, "lab_api_response.amqp", amqp_lab_api_response);
|
|
139
146
|
return response;
|
|
140
147
|
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* This function is used publish billing events into the exchange.
|
|
151
|
+
* @param {Object} amqp_lab_api_response
|
|
152
|
+
* @returns
|
|
153
|
+
*/
|
|
154
|
+
async publishBillingEvents(billing_events) {
|
|
155
|
+
const response = await AmqpController.publishMessage(hv_exchange, "billing", billing_events);
|
|
156
|
+
return response;
|
|
157
|
+
}
|
|
141
158
|
async publishPendingMessageInCache() {
|
|
142
159
|
return await AmqpController.publishPendingMessageInCache();
|
|
143
160
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "message-brokers",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.3",
|
|
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",
|