hapi-rabbit
hapi-rabbit copied to clipboard
Question: Plugin vs Native Rabbit
This may be a dumb question but I'm not sure I understand what you get by making this a plugin versus just using a native RabbitMQ module? I'd really appreciate it if someone can explain this to me.
Thanks
hey, thanks for your question. the package should simplify the usage of rabbitmq. I've created it for my own projects. there are several routing options and conventions that I don't want repeat every time I want to publish a message.
for example the first option is much shorter and easier to understand than the second option:
##option 1
rabbit.createContext(function(err, context){
if(err){
console.log('err', err);
}
rabbit.publish(context, 'exchange', 'messageType', 'message', function(err, data){
console.log('messageObject', data);
});
});
##option 2
var pub = context.socket('PUB', {routing: options.routing});
var messageObject = {
type: messageType,
data: message
};
pub.connect(exchange, function () {
if(options.hasOwnProperty('extras')) {
for (var key in options.extras) {
pub.setsockopt(key, options.extras[key]);
}
}
pub.publish(exchange + '.' + messageType, JSON.stringify(messageObject));
callback(null, messageObject);
});