Nestjstools Messaging Docs
  • Introduction
    • What is this library?
    • Supported message brokers
  • Getting Started
    • Installation
    • Initialize Module
    • Message Handler
    • Disaptch a message
  • Components
    • Message Handlers
    • Normalizers
    • Exception Listeners
    • Middlewares
    • Message Bus
    • Channel
  • Broker integration
    • RabbitMQ
    • Redis
    • Google PubSub
    • Amazon SQS
    • Nats
  • Best practice
    • CQRS based on RabbitMQ
    • Create wrapper class for Message Bus
    • Consumer as the background process
Powered by GitBook
On this page
  • 🧩 Defining the Messaging Module
  • 🔧 Starter Setup
  • 📌 Notes
  • 🚀 What’s Happening Here?
Export as PDF
  1. Getting Started

Initialize Module

🧩 Defining the Messaging Module

To use @nestjstools/messaging in your application, you need to register the MessagingModule in your root module (usually AppModule). This will make the messaging functionality available across all other modules in your app.

🔧 Starter Setup

import { Module } from '@nestjs/common';
import { MessagingModule, InMemoryChannelConfig } from '@nestjstools/messaging';


@Module({
  imports: [
    MessagingModule.forRoot({
      buses: [
        {
          name: 'my-channel.bus',
          channels: ['my-channel'],
        },
      ],
      channels: [
        new InMemoryChannelConfig({
          name: 'my-channel',
        }),
      ],
      debug: true,
    }),
  ],
})
export class AppModule {}

📌 Notes

  • MessagingModule.forRoot(...) registers the messaging system globally, meaning you don't need to import it in feature modules.

  • You must define at least one bus and one channel.

  • InMemoryChannelConfig our app will works on in-memory message transport layer.

  • Setting debug: true enables verbose logging to help with debugging message flow.

🚀 What’s Happening Here?

Property
Description

buses

Defines logical buses for message routing.

channels

Configures message channels (e.g., in-memory, Kafka, etc.).

debug

Enables or disables debug logging.

my-channel

A simple in-memory channel used by the message.bus.

⚠️ Important: Make sure this is defined in your AppModule or the main/root module to ensure messaging is globally available.

PreviousInstallationNextMessage Handler

Last updated 9 days ago