> 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/getting-started/initialize-module.md).

# 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

```ts
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 {}
```

### &#x20;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.

### &#x20;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.


---

# 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/getting-started/initialize-module.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.
