Skip to content

The Service Bus that you needed

Fully-typed Service Bus for Node.js fueled by fancy Middlewares, Envelopes and Stamps.

Built for simplicity and performance

Easy to use

Simple, pragmatic, super lightweight, no magic, just what you need and all Open Source.

Agnostic

You can use it with any framework or library, wether you’re fully backend or backend for frontend, we got you covered.

Envelopes and Stamps

Handle cross-cutting concerns with Envelopes and Stamps.

Type-safe

Define your query, command or event. The bus instance is fully typed. (You’ll have auto-completion for free!)

In a nutshell

  1. Install it

    Terminal window
    pnpm add missive.js
  2. Define your handler for query, command or event

    // the Types to use in the bus configuration
    type Command = { email: string };
    type Result = Awaited<ReturnType<typeof handler>>;
    export type Definition = CommandHandlerDefinition<'createUser', Command, Result>;
    // the handler to handle the intent
    const handler = async (envelope: Envelope<Command>, deps: Deps) => {
    const { email } = envelope.message;
    await deps.mailer('subject', email, 'plop', { html: 'html', text: 'text' });
    return { success: true };
    };
    // the factory to create the handler with the dependencies you may need
    export const Factory = (deps: Deps) => (query: Envelope<Command>) => handler(query, deps);
  3. Create a bus instance with all your definitions

    type CommandHandlerRegistry = SendRegistrationEmailDefinition & SendNotificationDefinition;
    const bus = createCommandBus<CommandHandlerRegistry>();
    bus.register('sendRegistrationEmail', Factory({ mailer }));
  4. Dispatch an intent

    const intent = bus.createCommand('sendRegistrationEmail', { email: 'plopix@example.com' });
    // ...
    const { envelope, result } = await bus.dispatch(intent);

Guides

Built-in Middlewares

Without Middlewares, a Service Bus is almost useless, we provide built-in middlewares that you can use out of the box. They are all optional and you can use them all together or just the ones you need. Middlewares provides a way to handle cross-cutting concerns. They are key to keep your code clean and maintainable. And most of all, they are easy to write and to use, and they can be generic!

That’s the power of Missive.js! Here are the built-in middlewares:

Validator Middleware

Validate the intent before it’s handled, and the result after it’s handled.

Read the doc

Logger Middleware

Easily add observability to your application by logging the messages (intent) and the full Envelope (with the Stamps) before and once handled (or errored) in the backend of your choice.

Read the doc

Caching Middleware

Caches results for faster access in future queries, reducing load and making it blazing fast with built-in Stale While Revalidating pattern.

Read the doc

Retry Middleware

Automatically retries processing an intent a specified number of times before considering it as failed, with different backoff strategy.

Read the doc

Webhook Middleware

The Webhook Middleware is going to send the envelope(s) to confirured webhook(s) (post processing). It’s another powerful way to decouple your system and to make it more resilient or to simply add Observability!.

Read the doc

Lock Middleware

It provide a way to lock the processing of a message based on something in the intent itself. For instance your could lock the command that touches a Cart.

Read the doc

Feature Flag Middleware

This middleware ensures that requests are conditionally processed based on the state of feature flags, enabling dynamic feature management, safer rollouts, and efficient A/B testing.

Read the doc

Mock Middleware

This middleware is pretty useful in development mode, to mock the result of a specific intent to bypass the handler.

Read the doc

Async Middleware

You can already do async if you don’t await in your handler, but this is next level to defer handling to a consumer. Push the intent to a queue and handle it asynchronously.

Read the doc

Framework Agnostic, see the examples


Missive.js. MIT License.
Powered by Astro Starlight.
Inspired by Symfony Messenger