hapi-rabbit icon indicating copy to clipboard operation
hapi-rabbit copied to clipboard

Question: Plugin vs Native Rabbit

Open astanciu opened this issue 10 years ago • 1 comments

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

astanciu avatar Sep 15 '15 18:09 astanciu

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);
});

aduis avatar Sep 26 '15 09:09 aduis