> For the complete documentation index, see [llms.txt](https://docs.nestjstools.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nestjstools.com/configuration.md).

# Configuration

`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:

```ts
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:

```ts
buses: [
  {
    name: 'command.message-bus',
    channels: ['rabbitmq-channel'],
  },
  {
    name: 'event.message-bus',
    channels: ['rabbitmq-channel', 'in-memory-channel'],
  },
];
```

***

## 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:

```ts
channels: [
  new InMemoryChannelConfig({
    name: 'in-memory-channel',
    middlewares: [],
  }),
];
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nestjstools.com/configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
