Disaptch a message
π€ Dispatching a Message
π Example: Dispatch from an HTTP Controller
import { Controller, Get } from '@nestjs/common';
import { MessageBus, IMessageBus, RoutingMessage } from '@nestjstools/messaging';
import { SendMessage } from './test/send-message';
@Controller()
export class AppController {
// You can inject any bus you've defined in your MessagingModule config
constructor(@MessageBus('message.bus') private readonly messageBus: IMessageBus) {}
@Get()
async dispatchMessage(): Promise<string> {
// Dispatching a SendMessage instance to the route 'your.message'
await this.messageBus.dispatch(
new RoutingMessage(new SendMessage('Message from HTTP request'), 'your.message'),
);
return 'Message dispatched successfully!';
}
}π¦ Components Explained
Component
Purpose
π‘ Best Practices
Last updated