Reputation: 908
I'm trying to use node-amqp.
When in the section of connection to rabbit an exception is thrown, I can get that exception but it restarts the connection to Rabbit forever.
Look at that:
amqp = require("amqp")
# Open a connection
conn = amqp.createConnection( {url: "amqp://localhost"} , {reconnect: true})
conn.on "ready", ->
console.log "Conn Ready"
conn.queue "queueX", {ack:true}, (queue) ->
console.log "Subscribed #{queue.name}"
assdsd() #calling non-exiting method. No exception is thrown but the connection is restarted
System loops on the errors thrown. I know this is because of {recconnect:true}. But I would like to be able to catch exceptions on my own. Any idea?
The output of my script is like this:
Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
....
Upvotes: 1
Views: 231
Reputation: 1051
You probably have an error somewhere, this can help you
# listen for conn errors
conn.on 'error', (err) ->
# print to check what went wrong
console.error err.stack
# exit script with error
# http://nodejs.org/api/process.html#process_process_exit_code
process.exit 1
Upvotes: 2