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

@abinashpatri/rabbitmq

v1.0.1

Published

Production-grade RabbitMQ event utility library

Readme

@abinashpatri/rabbitmq

Production-grade RabbitMQ event utility library for TypeScript and JavaScript services.

Highlights

  • RabbitMQ-only API surface.
  • Durable exchanges/queues with configurable retry and DLQ topology.
  • Confirm-channel publishing for safer delivery semantics.
  • Non-blocking retries using delayed redelivery via TTL + dead-letter routing.
  • Scoped clients for multi-service, multi-tenant, and test isolation.
  • CJS + ESM + bundled .d.ts types.

Install

npm install @abinashpatri/rabbitmq

Compatibility

  • Node.js: >=18
  • Runtime: CommonJS and ESM
  • Types: bundled TypeScript declarations

Import Patterns

// Root namespace import
import { rabbitMQ } from "@abinashpatri/rabbitmq";

// Subpath import
import * as rabbitMQApi from "@abinashpatri/rabbitmq/rabbitMQ";

Quick Start (TypeScript)

import { rabbitMQ } from "@abinashpatri/rabbitmq";

type InvoiceCreatedEvent = {
  eventId: string;
  invoiceId: string;
  customerId: string;
  amount: number;
};

await rabbitMQ.connect({
  url: "amqp://localhost",
  reconnect: {
    enabled: true,
    baseDelayMs: 1000,
    maxDelayMs: 30000,
    jitterMs: 250,
  },
});

await rabbitMQ.publish<InvoiceCreatedEvent>({
  exchange: "billing.events",
  routingKey: "invoice.created",
  messageId: "evt_10",
  type: "invoice.created",
  appId: "billing-service",
  message: {
    eventId: "evt_10",
    invoiceId: "inv_1",
    customerId: "cust_1",
    amount: 42,
  },
});

const consumer = await rabbitMQ.consume<InvoiceCreatedEvent>({
  exchange: "billing.events",
  queue: "notifications.invoice.created",
  routingKey: "invoice.created",
  prefetch: 20,
  retryLimit: 5,
  retryBaseDelayMs: 500,
  retryBackoffMultiplier: 2,
  retryMaxDelayMs: 45000,
  retryJitterMs: 250,
  handler: async (event) => {
    console.log("processing invoice", event.invoiceId);
  },
});

process.on("SIGTERM", async () => {
  await consumer.disconnect();
  await rabbitMQ.disconnect();
  process.exit(0);
});

Quick Start (JavaScript)

const { rabbitMQ } = require("@abinashpatri/rabbitmq");

async function run() {
  await rabbitMQ.connect("amqp://localhost");

  await rabbitMQ.publish({
    exchange: "shipping.events",
    routingKey: "shipment.created",
    messageId: "evt_200",
    message: {
      eventId: "evt_200",
      shipmentId: "ship_1",
      orderId: "order_1",
    },
  });

  return rabbitMQ.consume({
    exchange: "shipping.events",
    queue: "tracking.shipment.created",
    routingKey: "shipment.created",
    retryLimit: 4,
    handler: async (event) => {
      console.log("tracking:", event.shipmentId);
    },
  });
}

run().catch(console.error);

API Reference

Root export

  • rabbitMQ namespace

RabbitMQ namespace

  • rabbitMQ.connect("amqp://...")
  • rabbitMQ.connect({ url, socketOptions?, clientProperties?, reconnect? })
  • rabbitMQ.disconnect()
  • rabbitMQ.publish({ exchange, routingKey?, message, headers?, messageId?, type?, appId?, persistent?, mandatory?, client? })
  • rabbitMQ.consume({ exchange, queue, routingKey?, handler, prefetch?, retryLimit?, retryBaseDelayMs?, retryBackoffMultiplier?, retryMaxDelayMs?, retryJitterMs?, deadLetterExchange?, deadLetterQueue?, deadLetterRoutingKey?, retryExchange?, retryQueue?, retryRoutingKey?, client? })
  • rabbitMQ.createRabbitMQClient()
  • rabbitMQ.createScopedRabbitMQClient()
  • rabbitMQ.getRetryHeaders(msg)
  • rabbitMQ.buildRetryHeaders(retryCount)
  • rabbitMQ.withRetryCount(options, retryCount)

Consumer controls returned by consume():

  • stop()
  • disconnect()

Reliability Semantics

  • Delivery semantics are at-least-once.
  • Publishing uses confirm channels (waitForConfirms) before returning.
  • Retries use delayed redelivery (message expiration) through retry queues.
  • Messages that exceed retry limit are dead-lettered to DLQ exchange/queue.
  • Handlers should be idempotent and safe for reprocessing.

Default Topology

For exchange = app.events and queue = worker.q:

  • Main exchange: app.events (topic)
  • Main queue: worker.q (durable)
  • Retry exchange: app.events.retry (topic)
  • Retry queue: worker.q.retry (durable)
  • DLQ exchange: app.events.dlq (topic)
  • DLQ queue: worker.q.dlq (durable)

All names can be overridden through consume() options.

Operational Guidance

  • Set prefetch based on downstream capacity (CPU, DB, external APIs).
  • Keep payloads JSON and include an immutable event identifier.
  • Emit metrics for retry count, DLQ volume, consumer lag, and handler latency.
  • Use scoped clients when multiple services/tenants run in one process.
  • Tune reconnect and retry settings per workload and failure profile.

License

MIT License.