Redis

🧩 Redis Channel Integration

The Redis extension for @nestjstools/messaging enables your NestJS application to send and receive asynchronous messages through Redis-backed queues. This is especially useful for lightweight messaging setups or when using Redis as a shared infrastructure component.


📦 Installation

Install the core and Redis messaging packages:

npm install @nestjstools/messaging @nestjstools/messaging-redis-extension

or

yarn add @nestjstools/messaging @nestjstools/messaging-redis-extension

⚙️ Example Configuration

import { MessagingModule } from '@nestjstools/messaging';
import { MessagingRedisExtensionModule, RedisChannelConfig } from '@nestjstools/messaging-redis-extension';
import { InMemoryChannelConfig } from '@nestjstools/messaging/channels';
import { SendMessageHandler } from './handlers/send-message.handler';

@Module({
  imports: [
    MessagingRedisExtensionModule,
    MessagingModule.forRoot({
      messageHandlers: [SendMessageHandler],
      buses: [
        {
          name: 'message.bus',
          channels: ['my-channel'],
        },
        {
          name: 'command.bus',
          channels: ['redis-command'],
        },
        {
          name: 'event.bus',
          channels: ['redis-event'],
        },
      ],
      channels: [
        new InMemoryChannelConfig({
          name: 'my-channel',
          middlewares: [],
          avoidErrorsForNotExistedHandlers: true,
        }),
        new RedisChannelConfig({
          name: 'redis-command',
          queue: 'command-queue',
          connection: {
            host: '127.0.0.1',
            port: 6379,
          },
          middlewares: [],
          avoidErrorsForNotExistedHandlers: false,
        }),
        new RedisChannelConfig({
          name: 'redis-event',
          queue: 'event-queue',
          connection: {
            host: '127.0.0.1',
            port: 6379,
          },
          middlewares: [],
          avoidErrorsForNotExistedHandlers: true,
        }),
      ],
      debug: true,
    }),
  ],
})
export class AppModule {}

Last updated