@api private
var classes = {
"amqp": module.exports.AMQPAscoltatore,
"memory": module.exports.MemoryAscoltatore,
"mqtt": module.exports.MQTTAscoltatore,
"redis": module.exports.RedisAscoltatore,
"zmq": module.exports.ZeromqAscoltatore,
"mongo": module.exports.MongoAscoltatore
};Builds an ascolatore based on the proper type.
It will encapsulate it in a PrefixAscolatore if a prefix key is
present.
The other options are passed through the constructor of the
Ascoltatore
type, it can be "amqp", "memory", "redis", "zmq", or just a class
that will be instantiated (i.e. with new).prefix, will be passed to the PrefixAscoltatore.json, it can be setted to false if you do not want your messages
to be wrapped inside JSON.any other option that the ascolatore constructor may need.
@api public
@param {Object} opts The options
@param {Function} done The callback that will be called when the
ascoltatore will be ready
module.exports.build = function build(opts, done) {
opts = opts || {};
if (typeof opts === "function") {
done = opts;
opts = {};
}
var Klass = null,
result = null;
Klass = (typeof opts.type == 'function') ? opts.type :
(classes[opts.type] || module.exports.MemoryAscoltatore);
result = new Klass(opts, module.exports);
if (opts.prefix) {
result = new module.exports.PrefixAscoltatore(opts.prefix, result);
}
if (opts.json !== false) {
result = new module.exports.JSONAscoltatore(result);
}
if (done) {
module.exports.util.defer(function() {
result.once("ready", function() {
done(result);
});
});
}
return result;
};Use an Ascoltatore as a global pub/sub broker inside
the current node process.
Everyone requiring ascoltatori can use it.
module.exports.use = function use(ascoltatore) {
["publish", "subscribe", "unsubscribe", "close", "on",
"removeListener", "registerDomain"
].forEach(function(f) {
module.exports[f] = ascoltatore[f].bind(ascoltatore);
});
util.aliasAscoltatore(this);
return this;
};The default global Ascoltatore is a MemoryAscoltatore.
module.exports.use(new module.exports.MemoryAscoltatore());You can require a shared mocha test to you if you want to develop
a custom Ascoltatore inside your app.
module.exports.behaveLikeAnAscoltatore = require("./behave_like_an_ascoltatore");
You can require any Ascolatore through this module.