rascal
Version:
A config driven wrapper for amqplib supporting multi-host connections, automatic error recovery, redelivery flood protection, transparent encryption / decryption, channel pooling and publication timeouts
30 lines (27 loc) • 807 B
JavaScript
const debug = require('debug')('rascal:tasks:initVhosts');
const _ = require('lodash');
const async = require('async');
const forwardEvents = require('forward-emitter');
const Vhost = require('../Vhost');
module.exports = _.curry((config, ctx, next) => {
ctx.vhosts = {};
async.eachSeries(
_.values(config.vhosts),
(vhostConfig, callback) => {
initVhost(vhostConfig, ctx.components, (err, vhost) => {
if (err) return callback(err);
vhost.setMaxListeners(0);
forwardEvents(vhost, ctx.broker);
ctx.broker._addVhost(vhost);
ctx.vhosts[vhostConfig.name] = vhost;
callback();
});
},
(err) => {
next(err, config, ctx);
}
);
});
function initVhost(config, components, next) {
Vhost.create(config, components, next);
}