inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
33 lines • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const BaseSingletonDefinition_1 = require("../ioc/objectdefinition/BaseSingletonDefinition");
const RabbitmqProducer_1 = require("./RabbitmqProducer");
class RabbitmqProducerPlugin {
constructor() {
this.name = 'RabbitmqProducerPlugin';
}
getName() {
return this.name;
}
willStart(app) {
if (!app.hasConfig('rabbitmq')) {
throw new Error('RabbitmqPlugin has been registered but could not find config using key "rabbitmq"');
}
const context = app.getContext();
const confs = context.getConfig('rabbitmq.producer');
const clientConf = context.getConfig('rabbitmq.client');
Object.keys(confs).forEach((key) => {
const clientType = 'producer';
const name = `${key}_${clientType}`;
const clientSingleton = new BaseSingletonDefinition_1.BaseSingletonDefinition(RabbitmqProducer_1.RabbitmqProducer, name);
clientSingleton.constructorParamByValue(clientConf);
clientSingleton.constructorParamByValue(name);
clientSingleton.constructorParamByValue(confs[key]);
clientSingleton.startFunction('init');
clientSingleton.stopFunction('close');
context.registerSingletons(clientSingleton);
});
}
}
exports.default = RabbitmqProducerPlugin;
//# sourceMappingURL=RabbitmqProducerPlugin.js.map