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
Was this helpful?