wrenchConfiguration

MessagingModule can be configured using MessagingModule.forRoot().

This configuration defines:

  • buses – logical message buses used by your application

  • channels – transports responsible for delivering messages

  • debug and logging behavior

  • consumer execution rules

Example configuration:

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

MessagingModule.forRoot({
  buses: [
    {
      name: 'event.message-bus',
      channels: ['in-memory-channel'],
    },
  ],
  channels: [
    new InMemoryChannelConfig({
      name: 'in-memory-channel',
    }),
  ],
  debug: false,
  logging: true,
});

MessagingModule.forRoot Options

Property
Description
Default

buses

Array of message buses defining routing and processing of messages.

[]

channels

Array of channel configurations used by the message buses.

[]

debug

Enables debug mode with additional logs useful during development.

false

logging

Enables logging for bus activity (e.g., message dispatching).

true

customLogger

Custom logger instance implementing MessagingLogger.

NestLogger

forceDisableAllConsumers

Disables all external consumers. Messages will only be processed using InMemoryChannel. Useful in testing environments.

false


Buses

A bus defines how messages are routed through your system.

You can create multiple buses for different responsibilities, for example:

  • command bus

  • event bus

  • query bus

Bus configuration

Property
Description
Default

name

Unique name of the message bus.

channels

List of channel names used by this bus.

[]

Example:


Channels

Channels represent transport layers responsible for delivering and receiving messages.

Examples of transports:

  • RabbitMQ

  • Redis

  • NATS

  • Google Pub/Sub

  • In-memory messaging

Each channel has its own configuration.


InMemoryChannelConfig

The InMemoryChannelConfig is the simplest channel implementation and is useful for:

  • development

  • testing

  • synchronous message execution

Properties

Property
Description
Default

name

Name of the in-memory channel.

middlewares

List of middlewares applied to messages passing through this channel.

[]

avoidErrorsForNotExistedHandlers

Prevent errors when no handler exists for a message.

false

normalizer

Custom message normalizer used before dispatching messages.

Default normalizer

Example:

Last updated

Was this helpful?