Bootstrap (Http, Worker mode)

πŸ“˜ Introduction

A simple wrapper to speed up messaging-based app setup in NestJS.

@nestjstools/messaging-bootstrap It is a lightweight utility that simplifies bootstrapping a messaging-enabled NestJS application.

Built on top of @nestjstools/messaging, it offers two main modes:

  • An HTTP server with integrated messaging publisher capabilities

  • A dedicated worker/microservice that runs only messaging consumers


βš™οΈ Installation

yarn add @nestjstools/messaging-bootstrap @nestjs/microservices

πŸš€ Quick Start

Create a file messaging-confg.ts

// messaging-confg.ts

import { MessagingRabbitmqExtensionModule } from '@nestjstools/messaging-rabbitmq-extension';
import { AmqpChannelConfig, ExchangeType } from '@nestjstools/messaging';
import { MessagingModuleConfig } from '@nestjstools/messaging-bootstrap';

export const Config: MessagingModuleConfig = {
  extensions: [
    MessagingRabbitmqExtensionModule
  ],
  buses: [
    { name: 'command.bus', channels: ['async-command'] }
  ],
  channels: [
    new AmqpChannelConfig({
      name: 'async-command',
      connectionUri: 'amqp://localhost',
      exchangeName: 'command.exchange',
      bindingKeys: ['command.#'],
      exchangeType: ExchangeType.TOPIC,
      queue: 'app.command',
      enableConsumer: false,
    }),
  ],
};

βœ… HTTP Server with Messaging Publisher

βœ… Worker/Microservice with Consumers


πŸ› οΈ 4. Configuration

All options are passed into the bootstrap function:

messaging options:

  • extensions: array of messaging extension modules (e.g. RabbitMQ) (optional)

  • buses: define one or more message buses

  • channels: define channel configs (e.g. AMQP)

nestApplicationOptions / nestMicroserviceOptions:

  • Directly passed to NestFactory.create or createMicroservice


πŸ“„ 5. Examples

Shared Configuration Pattern

Then reuse in both main.ts and worker.ts.


⚠️ 7. Common Pitfalls

❌ Do not use MessagingModule.forRoot() manually

The bootstrap library already handles it for you. Including it manually will lead to duplicate initialization and unexpected bugs.

Correct usage:

Instead, let the bootstrap function handle it automatically.

Last updated