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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rmha-nestjs

v1.0.0

Published

NestJS RabbitMQ package - Resilient Message Handling Architecture

Readme

rmha-nestjs

A modular and production-ready Outbox/Inbox, Event-Driven Messaging, and RabbitMQ integration for NestJS and TypeORM/MikroORM

npm version npm downloads


Why rmha-nestjs?

  • SOLID event-driven microservice architecture, built for real-world complexity
  • Transparent Outbox pattern and Inbox deduplication with database persistency
  • Effortless RabbitMQ integration (publish, consume, auto-retry, dead-letter)
  • Works with both TypeORM and MikroORM
  • Zero-coupling: Bring your entities/repositories, plug & go
  • CLI-friendly: run as microservice, worker, batch, or standalone
  • Designed and used by engineers for large-scale, distributed NestJS applications

Features

  • Outbox pattern: Safe, atomic message publication from DB events
  • Inbox pattern: Exactly-once handling for incoming events
  • RabbitMQ: Fanout, direct, retry and error queues managed
  • Plug-in ORM: Integrate with either TypeORM or MikroORM
  • Customizable: Bring your own event entity, handler, repository adapter
  • Fully typed: TypeScript-first for safe building
  • Easy testing: Minimal bootstrap, full CLI
  • Highly configurable: All exchanges, queues, and routing configurable via options/env

Installation

npm install rmha-nestjs typeorm mikro-orm amqplib

You will also need your own entities and repositories, depending on TypeORM or MikroORM.


Quickstart

Import and configure the module in your AppModule or CLI Module:

import { RabbitmqModule } from 'rmha-nestjs';

@Module({
  imports: [
    RabbitmqModule.forRoot({
      username: process.env.RABBITMQ_USERNAME,
      password: process.env.RABBITMQ_PASSWORD,
      dsn: process.env.RABBITMQ_DSN,
      appName: process.env.APP_NAME,
      fanoutExchange: process.env.RABBITMQ_FANOUT_EXCHANGE,
      directExchange: process.env.RABBITMQ_DIRECT_EXCHANGE,
      primaryQueue: 'hospital.patient',
      retryQueue: 'hospital.patient.retry',
      retryBindingKey: 'hospital.patient.retry',
      errorBindingKey: 'hospital.dead-letter',
      heartbeatInterval: 30,
      delayedRetriesNumber: 3,
      immediateRetriesNumber: 5,
      retryQueueMessageTtl: 10000,
      consumeMessageLimit: 10,
      dispatchMessageLimit: 10,
      // outboxRepoProvider/inboxRepoProvider / messageHandlerRegistryProvider: see docs!
    }),
  ],
})
export class AppModule {}

For usage with TypeORM/MikroORM, see examples directory.


Outbox Pattern Example

const outboxEntity = new OutboxMessage({...});
await repo.storeOutboxMessage(outboxEntity, transactionalEntityManager);
// Later: rmha-nestjs dispatch picks unsent events and publishes to RabbitMQ

Inbox Pattern Example

await repo.storeInboxMessage({
  message_id: message.messageId,
  handler_name: handler.constructor.name,
}, transactionalEntityManager);
// Ensures deduplication for exactly once

CLI Usage

Dispatch Outbox

node dist/path/to/cli.patient.js dispatch-messages

Consume Inbox

node dist/path/to/cli.doctor.consumer.js consume-messages

Configuration

All options can be set via forRoot() or environment variables.


Advanced

  • Custom repository adapters for TypeORM/MikroORM
  • Completely pluggable: inject your own domain logic, adapters, events
  • Use as library or as dedicated worker/CLI

Documentation & Examples


Contributing

PRs, issues, suggestions welcome


Tags

event-driven, nestjs, rabbitmq, outbox, inbox, typeorm, mikroorm, microservices, distributed-systems, reliable-messaging, cli, fanout, direct, dead-letter, transactional, deduplication, nodejs, queue, scalable


License

MIT