@nestjstools/messaging
Version:
Simplifies asynchronous and synchronous message handling with support for buses, handlers, channels, and consumers. Build scalable, decoupled applications with ease and reliability.
33 lines • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessageHandlerRegistry = void 0;
const handler_for_message_not_found_exception_1 = require("../exception/handler-for-message-not-found.exception");
class MessageHandlerRegistry {
constructor() {
this.registry = new Map();
}
register(names, handler) {
names.forEach((name) => {
this.registerSingle(name, handler);
});
}
registerSingle(name, handler) {
if (this.registry.has(name)) {
const bucket = this.registry.get(name);
if (bucket.includes(handler)) {
return;
}
this.registry.get(name).push(handler);
return;
}
this.registry.set(name, [handler]);
}
getByRoutingKey(routingKey) {
if (!this.registry.has(routingKey)) {
throw new handler_for_message_not_found_exception_1.HandlerForMessageNotFoundException(routingKey);
}
return this.registry.get(routingKey);
}
}
exports.MessageHandlerRegistry = MessageHandlerRegistry;
//# sourceMappingURL=message-handler.registry.js.map