inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
62 lines • 3.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const RabbitmqProducer_1 = require("./RabbitmqProducer");
const RabbitmqConsumer_1 = require("./RabbitmqConsumer");
const RabbitmqMgtHttpApi_1 = require("./RabbitmqMgtHttpApi");
const RabbitmqHealthCheck_1 = require("./RabbitmqHealthCheck");
class RabbitmqClientPlugin {
constructor() {
this.name = 'RabbitmqClientPlugin';
}
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 clientConf = context.getConfig('rabbitmq.client');
// register health check
const mgtAPI = new index_1.BaseSingletonDefinition(RabbitmqMgtHttpApi_1.RabbitmqMgtHttpApi);
context.registerSingletons(mgtAPI);
const rhc = new index_1.BaseSingletonDefinition(RabbitmqHealthCheck_1.RabbitmqHealthCheck, 'HC_rabbitmq');
rhc.constructorParamByValue('rabbitmq');
context.registerDefinition(rhc);
if (context.hasConfig('rabbitmq.producer')) {
const producerConfs = context.getConfig('rabbitmq.producer');
Object.keys(producerConfs).forEach((key) => {
const TypeConsumer = 'producer';
const name = `${key}_${TypeConsumer}`;
const clientSingleton = new index_1.BaseSingletonDefinition(RabbitmqProducer_1.RabbitmqProducer, name);
clientSingleton.constructorParamByValue(clientConf);
clientSingleton.constructorParamByValue(name);
clientSingleton.constructorParamByValue(producerConfs[key]);
clientSingleton.setPropertyByValue('shutdownFunction', () => context.lcStop());
clientSingleton.startFunction('init');
clientSingleton.stopFunction('close');
context.registerSingletons(clientSingleton);
});
}
if (context.hasConfig('rabbitmq.consumer')) {
const consumerConfs = context.getConfig('rabbitmq.consumer');
Object.keys(consumerConfs).forEach((key) => {
const clientTypeConsumer = 'consumer';
const name = `${key}_${clientTypeConsumer}`;
const consumerSingleton = new index_1.BaseSingletonDefinition(RabbitmqConsumer_1.RabbitmqConsumer, name);
consumerSingleton.constructorParamByValue(clientConf);
consumerSingleton.constructorParamByValue(name);
consumerSingleton.constructorParamByValue(consumerConfs[key]);
consumerSingleton.constructorParamByRef(consumerConfs[key]['messageHandler']);
consumerSingleton.setPropertyByValue('shutdownFunction', () => context.lcStop());
consumerSingleton.startFunction('init');
consumerSingleton.stopFunction('close');
consumerSingleton.withLazyLoading(false);
context.registerSingletons(consumerSingleton);
});
}
}
}
exports.default = RabbitmqClientPlugin;
//# sourceMappingURL=RabbitmqClientPlugin.js.map