message-brokers 1.2.0 → 1.3.1
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 +9 -2
- package/lib/configs/mqConfigs.js +12 -1
- package/lib/message-brokers.js +22 -2
- package/lib/rabbitmq/rabbitmq.helper.js +3 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -91,12 +91,13 @@ const client = new MongoClient(mongoUrl, {
|
|
|
91
91
|
|
|
92
92
|
const mongoConnectionHolder = { connection: null };
|
|
93
93
|
|
|
94
|
-
client
|
|
94
|
+
client
|
|
95
|
+
.connect()
|
|
95
96
|
.then(() => {
|
|
96
97
|
console.log("✅ MongoDB connected!");
|
|
97
98
|
mongoConnectionHolder.connection = client.db(dbName);
|
|
98
99
|
})
|
|
99
|
-
.catch(error => console.error("❌ MongoDB connection failed:", error));
|
|
100
|
+
.catch((error) => console.error("❌ MongoDB connection failed:", error));
|
|
100
101
|
|
|
101
102
|
const messageBrokers = new MessageBrokers(mongoConnectionHolder);
|
|
102
103
|
```
|
|
@@ -127,4 +128,10 @@ messageBrokers.publishHarStub(har_stub);
|
|
|
127
128
|
|
|
128
129
|
// Publish raw_queue
|
|
129
130
|
messageBrokers.publishRawQueue(raw_queue);
|
|
131
|
+
|
|
132
|
+
// Publish har_stub_with_route_params
|
|
133
|
+
messageBrokers.publishHarStubWithRouteParams(har_stub_to_report_gen);
|
|
134
|
+
|
|
135
|
+
// Publish reportgen_response
|
|
136
|
+
messageBrokers.publishReportgenResponse(rg_response);
|
|
130
137
|
```
|
package/lib/configs/mqConfigs.js
CHANGED
|
@@ -15,7 +15,18 @@ const mqConfigs = [{
|
|
|
15
15
|
}, {
|
|
16
16
|
queueName: "raw-queue-processor",
|
|
17
17
|
routingKeyList: ["raw_queue"],
|
|
18
|
-
priorityQueue:
|
|
18
|
+
priorityQueue: true,
|
|
19
|
+
maxPriority: 5
|
|
20
|
+
}, {
|
|
21
|
+
queueName: "har-stub-processor",
|
|
22
|
+
routingKeyList: ["har_stub_to_report_gen"],
|
|
23
|
+
priorityQueue: true,
|
|
24
|
+
maxPriority: 5
|
|
25
|
+
}, {
|
|
26
|
+
queueName: "report-gen-response-processor",
|
|
27
|
+
routingKeyList: ["rg_response"],
|
|
28
|
+
priorityQueue: true,
|
|
29
|
+
maxPriority: 5
|
|
19
30
|
}
|
|
20
31
|
// Example for priority queue.
|
|
21
32
|
// {
|
package/lib/message-brokers.js
CHANGED
|
@@ -110,8 +110,28 @@ class MessageBrokers {
|
|
|
110
110
|
* @param {Object} raw_queue
|
|
111
111
|
* @returns
|
|
112
112
|
*/
|
|
113
|
-
async publishRawQueue(raw_queue) {
|
|
114
|
-
const response = await AmqpController.publishMessage(hv_exchange, "raw_queue", raw_queue);
|
|
113
|
+
async publishRawQueue(raw_queue, priority) {
|
|
114
|
+
const response = await AmqpController.publishMessage(hv_exchange, "raw_queue", raw_queue, priority);
|
|
115
|
+
return response;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* This function is used to publish request that parser sends to report_gen into the exchange.
|
|
120
|
+
* @param {Object} har_stub_to_report_gen
|
|
121
|
+
* @returns
|
|
122
|
+
*/
|
|
123
|
+
async publishHarStubWithRouteParams(har_stub_to_report_gen, priority) {
|
|
124
|
+
const response = await AmqpController.publishMessage(hv_exchange, "har_stub_to_report_gen", har_stub_to_report_gen, priority);
|
|
125
|
+
return response;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* This function is used to publish report_gen's response to parser's request into the exchange.
|
|
130
|
+
* @param {Object} rg_response
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
async publishReportgenResponse(rg_response, priority) {
|
|
134
|
+
const response = await AmqpController.publishMessage(hv_exchange, "rg_response", rg_response, priority);
|
|
115
135
|
return response;
|
|
116
136
|
}
|
|
117
137
|
async publishPendingMessageInCache() {
|
|
@@ -44,7 +44,9 @@ RabbitMQHelper.initializeAndBindQueue = async (rabbitmqChannel, exchangeName, qu
|
|
|
44
44
|
await rabbitmqChannel.assertQueue(queueName, {
|
|
45
45
|
durable: true,
|
|
46
46
|
...(priorityQueue && {
|
|
47
|
-
|
|
47
|
+
arguments: {
|
|
48
|
+
'x-max-priority': maxPriority
|
|
49
|
+
}
|
|
48
50
|
})
|
|
49
51
|
});
|
|
50
52
|
await queueLogger(`${queueName} queue created!`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "message-brokers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"install_deps": "NODE_ENV='development' yarn",
|
|
15
15
|
"build": "babel ./src -d ./lib && cp -r ./src/types/message-brokers.d.ts ./lib/types",
|
|
16
|
+
"watch": "babel ./src -d ./lib --watch & cp -r ./src/types/message-brokers.d.ts ./lib/types",
|
|
16
17
|
"prepublishOnly": "npm run build"
|
|
17
18
|
},
|
|
18
19
|
"repository": "https://code.360hvpl.com/development/message-brokers.git",
|