Create wrapper class for Message Bus
🚀 Messaging Wrapper Module
📦 Purpose
import { IMessageBus, RoutingMessage } from '@nestjstools/messaging';
/**
* A simplified interface for dispatching messages through a configured message bus.
* Encapsulates routing logic to keep controllers and services clean.
*/
export class InternalMessageBus {
constructor(private readonly messageBus: IMessageBus) {}
/**
* Dispatch a message using the given routing key.
*
* @param message The payload (command/event/etc.)
* @param routingKey The message routing key used by the bus
*/
async dispatch(message: object, routingKey: string): Promise<void> {
await this.messageBus.dispatch(new RoutingMessage(message, routingKey));
}
}🧱 Module Setup
🧩 Dependency Injection Tokens
🧪 Usage in a Controller
Last updated