Created
November 7, 2013 20:23
-
-
Save thelinuxlich/7361235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rabbitConnection = amqp.createConnection(config.amqp,{reconnect: false}),rabbitExchange,rabbitActiveHost = config.amqp.host,rabbit_config = JSON.parse(JSON.stringify(config.amqp)); | |
rabbitConnection.on('error', function (err) { | |
winston.error('Connection to rabbit failed:' + config.amqp.host); | |
if(!!config.secondary_amqp_host) { | |
rabbitActiveHost = (rabbitActiveHost == config.amqp.host ? config.secondary_amqp_host : config.amqp.host); | |
rabbit_config.host = rabbitActiveHost; | |
winston.log("info","Closing actual connection"); | |
rabbitConnection.end(); | |
} | |
}); | |
rabbitConnection.on('ready', function () { | |
winston.log('info', "Connected to Rabbit on "+rabbitActiveHost); | |
rabbitExchange = rabbitConnection.exchange(config.amqp.exchange, { | |
confirm: true, | |
autoDelete: false, | |
durable: true // We dont want the exchanges to be removed if node is exited | |
}, function() { | |
winston.log('info', "Connection to exchange done: " + config.amqp.exchange); | |
} | |
); | |
}); | |
rabbitConnection.on("close",function(){ | |
winston.log('info','Switching rabbit connection host to ' + rabbitActiveHost); | |
rabbitConnection.connect(rabbit_config); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment