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

@boringnode/bus

v0.10.0

Published

A simple and lean driver-based service bus implementation

Readme

typescript-image gh-workflow-image npm-image npm-download-image license-image

@boringnode/bus is a service bus implementation for Node.js. It is designed to be simple and easy to use.

Currently, it supports the following transports:

Table of Contents

Installation

npm install @boringnode/bus

The Redis and MQTT transports rely on optional peer dependencies. Install the client of the transport you use.

npm install ioredis # for the Redis transport
npm install mqtt # for the MQTT transport

If your project has neither ioredis nor mqtt installed and uses skipLibCheck: false, import types from @boringnode/bus/types/core. @boringnode/bus/types/main also re-exports the Redis and MQTT types.

Usage

The module exposes a manager that can be used to register buses.

import { BusManager } from '@boringnode/bus'
import { redis } from '@boringnode/bus/transports/redis'
import { mqtt } from '@boringnode/bus/transports/mqtt'
import { memory } from '@boringnode/bus/transports/memory'

const manager = new BusManager({
  default: 'main',
  transports: {
    main: {
      transport: memory(),
    },
    redis: {
      transport: redis({
        host: 'localhost',
        port: 6379,
      }),
    },
    mqtt: {
      transport: mqtt({
        host: 'localhost',
        port: 1883,
      }),
    },
  }
})

Once the manager is created, you can subscribe to channels and publish messages. A bus does not receive the messages it publishes itself, so the subscriber and the publisher usually live in different processes, connected through a shared transport like Redis.

// In one process
await manager.use('redis').subscribe('channel', (message) => {
  console.log('Received message', message)
})

// In another process
await manager.use('redis').publish('channel', 'Hello world')

The memory transport only delivers messages to other buses of the same process.

An error thrown or rejected by a handler does not crash the process, and other handlers still run. The bus catches it and logs it when NODE_DEBUG=boringnode:bus is set. Catch errors inside the handler if you need to react to them.

By default, the bus will use the default transport. You can specify different transport by using the use method.

manager.use('redis').publish('channel', 'Hello world')
manager.use('mqtt').publish('channel', 'Hello world')

MQTT topic filters

The MQTT transport accepts topic filters with the + and # wildcards, and calls the handlers of every filter matching a received topic. When filters overlap, such as orders/+ and orders/#, some brokers like Mosquitto and EMQX send one copy of the message per matching subscription, and the handlers of these filters are called once per copy. This happens with MQTT 5 too, so avoid overlapping filters when a handler must run once per message.

Without the manager

If you don't need multiple buses, you can create a single bus directly by importing the transports and the Bus class.

import { Bus } from '@boringnode/bus'
import { RedisTransport } from '@boringnode/bus/transports/redis'

const transport = new RedisTransport({
  host: 'localhost',
  port: 6379,
})

const bus = new Bus(transport, {
  retryQueue: {
    retryInterval: '100ms'
  }
})

Retry Queue

The bus also supports a retry queue. When a message fails to be published, it will be moved to the retry queue.

For example, your Redis server is down.

const manager = new BusManager({
  default: 'main',
  transports: {
    main: {
      transport: redis({
        host: 'localhost',
        port: 6379,
      }),
      retryQueue: {
        retryInterval: '100ms'
      }
    },
  }
})

manager.use('main').publish('channel', 'Hello World')

The message will be moved to the retry queue and will be retried every 100ms.

The retry queue only retries publishing. Redis and MQTT pub/sub deliver messages at most once: a successful publish does not mean a subscriber received the message, and subscribers that are disconnected when it is published never get it. If you need guaranteed delivery, use a durable mechanism such as Redis Streams or message acknowledgements in your application.

Redis Cluster does not guarantee message ordering either: it sends a keyless PUBLISH to a random node, so a subscriber can receive messages published one after the other in a different order.

You have multiple options to configure the retry queue.

export interface RetryQueueOptions {
  // Enable the retry queue (default: true)
  enabled?: boolean
  
  // Ignore a message when the same payload is already queued for the same channel (default: true)
  removeDuplicates?: boolean
  
  // The maximum size of the retry queue (default: null)
  maxSize?: number | null
  
  // The interval between each retry (default: false)
  retryInterval?: Duration | false
}

Test helpers

The module also provides some test helpers to make it easier to test the code that relies on the bus. First, you can use the MemoryTransport to create a bus that uses an in-memory transport.

You can also use the ChaosTransport to simulate a transport that fails randomly, in order to test the resilience of your code.

import { Bus } from '@boringnode/bus'
import { MemoryTransport } from '@boringnode/bus/transports/memory'
import { ChaosTransport } from '@boringnode/bus/test_helpers'

const buggyTransport = new ChaosTransport(new MemoryTransport())
const bus = new Bus(buggyTransport)

/**
 * Now, every time you will try to publish a message, the transport 
 * will throw an error.
 */
buggyTransport.alwaysThrow()