Message Bus
π¬ MessageBus
π What Is the MessageBus?
π Injecting the MessageBus
Example
import { Controller, Get } from '@nestjs/common';
import { MessageBus, IMessageBus, RoutingMessage } from '@nestjstools/messaging';
import { SendMessage } from './messages/send-message';
@Controller()
export class AppController {
constructor(@MessageBus('message.bus') private readonly messageBus: IMessageBus) {}
@Get()
async dispatch(): Promise<string> {
await this.messageBus.dispatch(
new RoutingMessage(new SendMessage('Hello World!'), 'your.message'),
);
return 'Message dispatched!';
}
}π§© RoutingMessage Structure
Example:
π‘ Bus-to-Channel Mapping
π One Bus, Many Channels
π Benefits of MessageBus
Feature
Benefit
Last updated
Was this helpful?