0

I currently forced to create a new RabbitMQ connection every time a user loads a page on my website.

This is creating a new TCP connection every time. However, i'm trying to reduce the number of TCP connections i make to Rabbit with the NodeJS AMQP plug in. Here is what i have:

var ex_conn = get_connection(uri); //http:rabbitm.com

if(ex_conn == false) {

    var tempConn = amqp.createConnection({
        url: uri
    });

    connections.push({
        host: uri,
        obj: tempConn
    });
}
else {

    var tempConn = ex_conn.obj;

}

The issue i'm running into is that if i try to do:

tempConn.on('ready', function() {

});

Then the ready function does not get triggered. I'm assuming, that is because the ready call back was already defined and it is not going to be re triggered. What i'm looking to do is bind a new queue by doing:

tempConn.queu('', {});

Any thoughts on how to get around this issue is much appreciated.

thanks.

Dani
  • 5,828
  • 2
  • 17
  • 21
  • I was able to resolve the issue by storing the connection object and if the connection already existed i directly call conn.queue instead of waiting on the ready function. – Dani Aug 19 '14 at 20:22
  • Can you please post your code? – Pritam Dec 31 '14 at 08:53
  • This is what i ended up doing: tempConn.on("ready", function() { callback(null, conn); }); the callback is something i pass to the get_connection method which gets called when a connection is ready. – Dani Jan 01 '15 at 22:27

0 Answers0