postwait / node-amqp

[UNMAINTAINED] node-amqp is an AMQP client for nodejs
MIT License
1.69k stars 357 forks source link

Handle Failure - AMQP NodeJs #400

Open PreethiBabu87 opened 9 years ago

PreethiBabu87 commented 9 years ago

Hi

Am using amqplib/callback_api. how can i list all the rabbit nodes in the connection url. Rabbit has 4 nodes. In C# i connect using the belwo con string which works. If one node fails the other node picks it up: "host=node1,node2,node3;username=test;password=test;prefetchcount=50" I want to perform the same thing using nodejs.But am not sure how to mention other nodes in the list. KINDLY HELP. Below is my code:

var amqp = require('amqplib/callback_api');
// if the connection is closed or fails to be established at all, we will reconnect
var amqpConn = null;
var start = function () {
    amqp.connect("amqp://test:test@node1:5672", function (err, conn) {
          //console.log(conn)
        if (err) {
            console.error("[AMQP]", err.message);
            return setTimeout(start, 1000);
        }
    conn.on("error", function (err) {
        if (err.message !== "Connection closing") {
            console.error("[AMQP] conn error", err.message);
        }
        });
        conn.on("close", function () {
            console.error("[AMQP] reconnecting");
            return setTimeout(start, 1000);
        });
        console.log("[AMQP] connected");
        amqpConn = conn;
        whenConnected();
    });
}