message-brokers 1.7.0 → 1.8.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 CHANGED
@@ -74,7 +74,7 @@ db.on("error", (err) => {
74
74
  console.error("❌ Mongoose connection error:", err);
75
75
  });
76
76
 
77
- const messageBrokers = new MessageBrokers(mongoConnectionHolder);
77
+ const messageBrokers = new MessageBrokers(mongoConnectionHolder, "app_name");
78
78
  ```
79
79
 
80
80
  #### 2. Native Mongodb driver initialization
@@ -101,7 +101,7 @@ client
101
101
  })
102
102
  .catch((error) => console.error("❌ MongoDB connection failed:", error));
103
103
 
104
- const messageBrokers = new MessageBrokers(mongoConnectionHolder);
104
+ const messageBrokers = new MessageBrokers(mongoConnectionHolder, "app_name");
105
105
  ```
106
106
 
107
107
  ## Usage
@@ -133,4 +133,7 @@ messageBrokers.publishRawQueue(raw_queue);
133
133
 
134
134
  // Publish notification_messages_logs
135
135
  messageBrokers.publishNotificationMessagesLogs(notification_messages_logs);
136
+
137
+ // Publish amqp_lab_api_response
138
+ messageBrokers.publishAmqpLabApiResponse(amqp_lab_api_response);
136
139
  ```
@@ -0,0 +1,11 @@
1
+ let activeApplication = "mb_app";
2
+ function setActiveApplication(activeApp) {
3
+ activeApplication = activeApp;
4
+ }
5
+ function getActiveApplication() {
6
+ return activeApplication;
7
+ }
8
+ module.exports = {
9
+ setActiveApplication,
10
+ getActiveApplication
11
+ };
@@ -2,10 +2,14 @@ require("dotenv").config();
2
2
  const package_loader = require("./package-loader");
3
3
  const AmqpController = require("./controllers/amqp.controller");
4
4
  const mbConfigs = require("./configs/mb.configs");
5
+ const {
6
+ setActiveApplication
7
+ } = require("./helpers/app.helper");
5
8
  const hv_exchange = "hv.exchange";
6
9
  class MessageBrokers {
7
- constructor(mongoConnectionHolder) {
10
+ constructor(mongoConnectionHolder, applicationName) {
8
11
  try {
12
+ setActiveApplication(applicationName || "mb_app");
9
13
  if (!mbConfigs.rabbitmqUrl) {
10
14
  throw new Error("RABBITMQ_URL is required for message brokers initialization.");
11
15
  }
@@ -1,10 +1,19 @@
1
1
  const mongoDB = require("../helpers/mongodb.helper");
2
+ const {
3
+ getActiveApplication
4
+ } = require("../helpers/app.helper");
2
5
  const DeadQueueService = {};
3
6
  DeadQueueService.storeFailureMessage = async failedMessage => {
4
7
  try {
5
8
  const db = await mongoDB();
6
9
  const collection = await db.collection("deadqueue");
7
- await collection.insertOne(failedMessage);
10
+ const applicationName = getActiveApplication();
11
+ const new_failed_message = {
12
+ ...failedMessage,
13
+ app_name: applicationName,
14
+ created_at: new Date()
15
+ };
16
+ await collection.insertOne(new_failed_message);
8
17
  console.log(`INFO: [${new Date().toLocaleString()}] [MQ]: ${failedMessage?.routingKey} added to dead_queue.`);
9
18
  return {
10
19
  success: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-brokers",
3
- "version": "1.7.0",
3
+ "version": "1.8.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",