message-brokers 1.6.0-beta.1 → 1.7.0
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/lib/configs/mqConfigs.js +4 -11
- package/lib/message-brokers.js +13 -31
- package/lib/rabbitmq/rabbitmq.helper.js +23 -2
- package/package.json +1 -2
package/lib/configs/mqConfigs.js
CHANGED
|
@@ -15,18 +15,11 @@ const mqConfigs = [{
|
|
|
15
15
|
}, {
|
|
16
16
|
queueName: "raw-queue-processor",
|
|
17
17
|
routingKeyList: ["raw_queue"],
|
|
18
|
-
priorityQueue:
|
|
19
|
-
maxPriority: 5
|
|
20
|
-
}, {
|
|
21
|
-
queueName: "har-stub-processor",
|
|
22
|
-
routingKeyList: ["har_stub_to_report_gen"],
|
|
23
|
-
priorityQueue: true,
|
|
24
|
-
maxPriority: 5
|
|
18
|
+
priorityQueue: false
|
|
25
19
|
}, {
|
|
26
|
-
queueName: "
|
|
27
|
-
routingKeyList: ["
|
|
28
|
-
priorityQueue:
|
|
29
|
-
maxPriority: 5
|
|
20
|
+
queueName: "v2.lab-data.queue",
|
|
21
|
+
routingKeyList: ["lab_api_response.amqp"],
|
|
22
|
+
priorityQueue: false
|
|
30
23
|
}
|
|
31
24
|
// Example for priority queue.
|
|
32
25
|
// {
|
package/lib/message-brokers.js
CHANGED
|
@@ -5,21 +5,13 @@ const mbConfigs = require("./configs/mb.configs");
|
|
|
5
5
|
const hv_exchange = "hv.exchange";
|
|
6
6
|
class MessageBrokers {
|
|
7
7
|
constructor(mongoConnectionHolder) {
|
|
8
|
-
this.mongoConnectionHolder = mongoConnectionHolder;
|
|
9
|
-
this.initialized = false;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// This function is to initialize rabbitmq
|
|
13
|
-
async init() {
|
|
14
8
|
try {
|
|
15
9
|
if (!mbConfigs.rabbitmqUrl) {
|
|
16
|
-
throw new Error("RABBITMQ_URL is
|
|
10
|
+
throw new Error("RABBITMQ_URL is required for message brokers initialization.");
|
|
17
11
|
}
|
|
18
|
-
|
|
19
|
-
await package_loader(this.mongoConnectionHolder, true);
|
|
20
|
-
this.initialized = true;
|
|
12
|
+
package_loader(mongoConnectionHolder, true);
|
|
21
13
|
} catch (error) {
|
|
22
|
-
|
|
14
|
+
package_loader(mongoConnectionHolder, false); // disable rabbitmq
|
|
23
15
|
}
|
|
24
16
|
}
|
|
25
17
|
|
|
@@ -118,38 +110,28 @@ class MessageBrokers {
|
|
|
118
110
|
* @param {Object} raw_queue
|
|
119
111
|
* @returns
|
|
120
112
|
*/
|
|
121
|
-
async publishRawQueue(raw_queue
|
|
122
|
-
const response = await AmqpController.publishMessage(hv_exchange, "raw_queue", raw_queue
|
|
123
|
-
return response;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* This function is used to publish request that parser sends to report_gen into the exchange.
|
|
128
|
-
* @param {Object} har_stub_to_report_gen
|
|
129
|
-
* @returns
|
|
130
|
-
*/
|
|
131
|
-
async publishHarStubWithRouteParams(har_stub_to_report_gen, priority) {
|
|
132
|
-
const response = await AmqpController.publishMessage(hv_exchange, "har_stub_to_report_gen", har_stub_to_report_gen, priority);
|
|
113
|
+
async publishRawQueue(raw_queue) {
|
|
114
|
+
const response = await AmqpController.publishMessage(hv_exchange, "raw_queue", raw_queue);
|
|
133
115
|
return response;
|
|
134
116
|
}
|
|
135
117
|
|
|
136
118
|
/**
|
|
137
|
-
* This function is used
|
|
138
|
-
* @param {Object}
|
|
119
|
+
* This function is used publish notification_messages_logs into the exchange.
|
|
120
|
+
* @param {Object} notification_messages_logs
|
|
139
121
|
* @returns
|
|
140
122
|
*/
|
|
141
|
-
async
|
|
142
|
-
const response = await AmqpController.publishMessage(hv_exchange, "
|
|
123
|
+
async publishNotificationMessagesLogs(notification_messages_logs) {
|
|
124
|
+
const response = await AmqpController.publishMessage(hv_exchange, "notification_messages_logs", notification_messages_logs);
|
|
143
125
|
return response;
|
|
144
126
|
}
|
|
145
127
|
|
|
146
128
|
/**
|
|
147
|
-
* This function is used publish
|
|
148
|
-
* @param {Object}
|
|
129
|
+
* This function is used publish amqp_lab_api_response into the exchange.
|
|
130
|
+
* @param {Object} amqp_lab_api_response
|
|
149
131
|
* @returns
|
|
150
132
|
*/
|
|
151
|
-
async
|
|
152
|
-
const response = await AmqpController.publishMessage(hv_exchange, "
|
|
133
|
+
async publishAmqpLabApiResponse(amqp_lab_api_response) {
|
|
134
|
+
const response = await AmqpController.publishMessage(hv_exchange, "lab_api_response.amqp", amqp_lab_api_response);
|
|
153
135
|
return response;
|
|
154
136
|
}
|
|
155
137
|
async publishPendingMessageInCache() {
|
|
@@ -29,8 +29,13 @@ RabbitMQHelper.initializePubSub = async () => {
|
|
|
29
29
|
});
|
|
30
30
|
await exchangeLogger(exchangeName);
|
|
31
31
|
for (const queueConfig of mq.queueConfigList) {
|
|
32
|
-
if (process.env.DATACLOAK_DISABLE && queueConfig.queueName
|
|
33
|
-
|
|
32
|
+
if (process.env.DATACLOAK_DISABLE === "true" && queueConfig.queueName.startsWith("datacloak.queue")) {
|
|
33
|
+
if (RABBITMQ_DEPLOYMENT_ENV) {
|
|
34
|
+
queue_name = `${queueConfig.queueName}.${RABBITMQ_DEPLOYMENT_ENV}`;
|
|
35
|
+
}
|
|
36
|
+
console.log(`Skipping queue ${queue_name} initialization due to DATACLOAK_DISABLE environment variable.`);
|
|
37
|
+
console.log(`Deleting queue ${queue_name} if it exists.`);
|
|
38
|
+
await RabbitMQHelper.deleteQueue(queue_name);
|
|
34
39
|
continue;
|
|
35
40
|
}
|
|
36
41
|
await RabbitMQHelper.initializeAndBindQueue(rabbitmqChannel, exchangeName, queueConfig);
|
|
@@ -150,4 +155,20 @@ RabbitMQHelper.publish = async (exchangeName, routingKey, message, priority = 0,
|
|
|
150
155
|
};
|
|
151
156
|
}
|
|
152
157
|
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* This function is used to delete queue.
|
|
161
|
+
* @param {String} queueName
|
|
162
|
+
* @returns
|
|
163
|
+
*/
|
|
164
|
+
RabbitMQHelper.deleteQueue = async queueName => {
|
|
165
|
+
try {
|
|
166
|
+
const rabbitmqChannel = await rabbitmq();
|
|
167
|
+
await rabbitmqChannel.deleteQueue(queueName);
|
|
168
|
+
console.log(`Queue ${queueName} deleted successfully`);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.log(`Error while deleting queue ${queueName}`);
|
|
171
|
+
console.error(error);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
153
174
|
module.exports = RabbitMQHelper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "message-brokers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
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",
|
|
@@ -14,7 +14,6 @@
|
|
|
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
16
|
"watch": "babel ./src -d ./lib --watch & cp -r ./src/types/message-brokers.d.ts ./lib/types",
|
|
17
|
-
"watch:local": "concurrently \"npm run watch\" \"npx nodemon --watch ./lib --ext js,json --exec 'docker restart parser_dev && docker restart report_gen_dev '\"",
|
|
18
17
|
"prepublishOnly": "npm run build"
|
|
19
18
|
},
|
|
20
19
|
"repository": "https://code.360hvpl.com/development/message-brokers.git",
|