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
Export as PDF
  1. Broker integration

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 {}
PreviousRabbitMQNextGoogle PubSub

Last updated 3 days ago