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

nestjs-bustransit

v0.3.3

Published

Production-ready NestJS message bus with RabbitMQ, featuring Saga Pattern with persistence (MongoDB/PostgreSQL), Routing Slips orchestration, and comprehensive retry strategies for reliable distributed systems

Downloads

574

Readme

NestJS Service Bus

A powerful NestJS library for building reliable distributed systems with RabbitMQ. Simplifies message-based communication with support for the Saga Pattern, Routing Slips, and comprehensive Retry Strategies for managing distributed transactions.

📚 Documentation

Why Use This Library?

In a microservices architecture, handling transactions that span across multiple services (distributed transactions) is a significant challenge. The Saga Pattern provides an effective solution for maintaining data consistency by orchestrating a sequence of local transactions, with the ability to roll back if any step fails.

This library offers:

  • Easy NestJS Integration: Leveraging NestJS features like dependency injection, decorators, and modules for seamless Service Bus configuration and usage.
  • Saga Pattern Implementation: Provides tools and structures to define, execute, and monitor Sagas, ensuring data consistency even when failures occur.
  • Production-Ready Saga Persistence: Database-backed state management with support for MongoDB, PostgreSQL, and in-memory storage, including optimistic locking and auto-archiving.
  • Routing Slips Pattern: Activity-based workflow coordination with automatic compensation for distributed transactions.
  • Comprehensive Retry Strategies: Four retry strategies (Immediate, Interval, Intervals, Exponential) at two levels (Retry + Redelivery).
  • RabbitMQ Powered: Utilizes RabbitMQ's performance and reliability as the message transport layer, supporting queuing, routing, and publish/subscribe.
  • Scalability: Designed to be easily extensible and customizable to meet specific project needs.
  • Robust Error Handling: Built-in error handling mechanisms help manage failure scenarios and trigger compensation steps within a Saga.

Getting Started

Installation

npm install nestjs-bustransit uuid
# or
yarn add nestjs-bustransit uuid

Roadmap

  • [x] RabbitMq Broker
  • [x] Retry Level 1 (Immediate, Interval, Intervals, Exponential)
  • [x] Retry Level 2 (Redelivery with all strategies)
  • [x] Saga pattern
  • [x] Saga compensation
  • [x] Saga state persistence (MongoDB, PostgreSQL, In-Memory)
  • [x] Routing slips pattern
  • [ ] Kafka broker

Core Features

🔄 Retry Strategies

Comprehensive retry mechanisms with 4 strategies (Immediate, Interval, Intervals, Exponential) at 2 levels (Retry + Redelivery). Handle transient failures gracefully with automatic backoff and requeuing.

→ Read the Retry Strategies Guide

📨 Consumer & Producer Configuration

Easy setup for message consumers and producers with NestJS dependency injection. Configure endpoints, prefetch counts, and retry policies with a fluent API.

→ See Configuration Examples

// Configure consumers and retry policies
x.AddConsumer(SubmitOrderConsumer);
x.UsingRabbitMq('my-app', (context, cfg) => {
    cfg.ReceiveEndpoint("orders-queue", e => {
        e.ConfigureConsumer(SubmitOrderConsumer, context, c => {
            c.UseMessageRetry(r => r.Immediate(5));
            c.UseRedelivery(r => r.Exponential(5, 5000, 2));
        });
    });
});

🎭 Saga Pattern & Compensation

Event-driven state machines with automatic compensation. Build complex workflows that maintain data consistency across distributed services. Define compensating actions that execute in reverse order when failures occur.

Key Features:

  • State machine orchestration
  • Event-driven transitions
  • Automatic LIFO compensation
  • Long-running process support

→ Read the Saga Compensation Guide → View Saga Examples

Saga Workflow

💾 Saga State Persistence

Production-ready state management for saga state machines with database persistence. Persist saga state across application restarts with support for multiple storage backends.

Key Features:

  • Multiple storage adapters (InMemory, MongoDB, PostgreSQL)
  • Optimistic locking for concurrent updates
  • Auto-archiving with configurable TTL
  • Retry logic with exponential backoff
  • Backward compatible (defaults to in-memory)
  • Async configuration support

→ Read the Saga Persistence Guide → Configuration Guide → Migration Guide

// Configure persistence for production
@Module({
  imports: [
    SagaPersistenceModule.forRoot({
      type: SagaPersistenceType.MongoDB,
      connection: {
        uri: 'mongodb://localhost:27017',
        database: 'bustransit',
        collectionName: 'saga_states'
      },
      autoArchive: true,
      archiveTTL: 86400 * 30 // 30 days
    }),
    BusTransit.AddBusTransit.setUp(bus => {
      bus.AddSagaStateMachine(OrderStateMachine, OrderState);
    })
  ]
})
export class AppModule {}

📋 Routing Slips Pattern

Activity-based workflow orchestration inspired by MassTransit's Routing Slips. Build dynamic, multi-service workflows with reusable activities and automatic compensation.

Key Features:

  • Reusable activity components
  • Dynamic runtime itineraries
  • Automatic LIFO compensation
  • Rich event system (Completed, Faulted, ActivityCompleted, etc.)
  • Variable passing between activities

→ Read the Routing Slips Guide → Quick Start Tutorial → View Routing Slip Examples

When to use:

  • Routing Slips: Multi-service workflows, dynamic orchestration, reusable activities
  • Saga Compensation: Complex state machines, long-running processes, event-driven flows

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.