Message Handler
π¬ Defining a Message & Message Handler
π¨ Define Your Message
// send-message.ts
export class SendMessage {
constructor(
public readonly content: string,
) {}
}π οΈ Define a Message Handler
import { Injectable } from '@nestjs/common';
import { MessageHandler, IMessageHandler, MessageResponse } from '@nestjstools/messaging';
import { SendMessage } from './send-message';
@Injectable()
@MessageHandler('your.message') // This should match the message route you publish to
export class SendMessageHandler implements IMessageHandler<SendMessage> {
async handle(message: SendMessage): Promise<MessageResponse | void> {
console.log(message.content);
// Add your business logic here
}
}π Multiple Routes
π§ Optional: Use @DenormalizeMessage() Decorator
@DenormalizeMessage() DecoratorLast updated