npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

message-brokers

v1.9.1

Published

This package contains functions to publish the messages into the message brokers like rabbitmq.

Downloads

1,186

Readme

message-brokers

npm version npm downloads node version

Message-Brokers is a package designed for managing RabbitMQ connections and operations. It simplifies the setup of queues and exchanges based on provided configurations and supports publishing messages to RabbitMQ with customizable routing keys and priorities. The package also integrates caching for better message management and retry mechanisms in case of failures.

Installation

Using npm

npm i message-brokers

Using yarn

yarn add message-brokers

Initialization

Set the following environment variables:

RABBITMQ_URL=amqp://admin:pwd@localhost:5672

(Optional)
ACTIVE_MESSAGE_BROKER=rabbitmq
# Defines the active message broker used by the system.
# Supported values: rabbitmq | redis (future support possible)

REDIS_PORT=6260
# Port used for Redis connection (used for caching / broker fallback mechanisms)

CACHING_ENABLED=true
# Enables/disables caching layer for message publishing and broker operations


RABBITMQ_DEPLOYMENT_ENV=stage
# Logical deployment identifier for shared RabbitMQ infrastructure.
# When set, it is appended to ALL RabbitMQ entities:
# - exchanges
# - queues
# - routing keys
#
# Example:
# base.queue → base.queue.stage
# base-key → base-key.stage
#
# Use this when multiple environments (stage/dev/prod) share the same RabbitMQ cluster.


DATACLOAK_DISABLE=true
# Disables Datacloak-related queues for non-production environments (e.g. stage/demo).
# When enabled, Datacloak queues will be skipped and removed if they exist.
# Useful for reducing unnecessary processing in shared or test deployments.


RABBITMQ_ISOLATED_NAMESPACE=prod-2
# Applies an isolation namespace ONLY to selected queues and routing keys.
#
# This is used together with an isolation prefix list (e.g. rabbitmqIsolatedQueues).
# If a queue/routing key matches the isolation rule, this namespace is appended:
#
# Example:
# messaging.queue → messaging.queue.prod-2
#
# Purpose:
# - Enables tenant-level or client-level isolation within the same broker
# - Prevents cross-communication between shared deployments
#
# Note:
# This does NOT apply globally — only to explicitly configured isolated queues/routing keys.
// ES5 Syntax
const MessageBrokers = require("message-brokers");
// ES6 Syntax
import MessageBrokers from "message-brokers";

const messageBrokers = new MessageBrokers();

Initialization with MongoDB for deadqueue

1. Mongoose initialization

const MessageBrokers = require("message-brokers");
const mongoose = require("mongoose");

const mongoConnectionHolder = { connection: null };

mongoose.connect("mongodb://localhost:27017/db");

const db = mongoose.connection;

db.on("connected", () => {
  console.log("✅ Mongoose connected!");
  mongoConnectionHolder.connection = db;
});

db.on("error", (err) => {
  console.error("❌ Mongoose connection error:", err);
});

const messageBrokers = new MessageBrokers(mongoConnectionHolder, "app_name");
await messageBrokers.init();

2. Native Mongodb driver initialization

const MessageBrokers = require("message-brokers");
const { MongoClient } = require("mongodb");

const mongoUrl = "mongodb://localhost:27017";
const dbName = "db";

const client = new MongoClient(mongoUrl, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const mongoConnectionHolder = { connection: null };

client
  .connect()
  .then(() => {
    console.log("✅ MongoDB connected!");
    mongoConnectionHolder.connection = client.db(dbName);
  })
  .catch((error) => console.error("❌ MongoDB connection failed:", error));

const messageBrokers = new MessageBrokers(mongoConnectionHolder, "app_name");
await messageBrokers.init();  

Usage

// Publish har
messageBrokers.publishHar(har);

// Publish har_meta
messageBrokers.publishHarMeta(har_meta);

// Publish lab_api_response
messageBrokers.publishLabApiResponse(lab_api_response);

// Publish purchase_details
messageBrokers.publishPurchaseDetails(purchase_details);

// Publish lab_location_data
messageBrokers.publishLabLocationData(lab_location_data);

// Publish input_object
messageBrokers.publishInputObject(input_object);

// Publish har_stub
messageBrokers.publishHarStub(har_stub);

// Publish raw_queue
messageBrokers.publishRawQueue(raw_queue);

// Publish notification_messages_logs
messageBrokers.publishNotificationMessagesLogs(notification_messages_logs);

// Publish amqp_lab_api_response
messageBrokers.publishAmqpLabApiResponse(amqp_lab_api_response);

// Publish billing_events
messageBrokers.publishBillingEvents(billing_events);