【问题标题】:No exception when node-amqpnode-amqp 时也不例外
【发布时间】:2014-09-08 16:18:56
【问题描述】:

我正在尝试使用 node-amqp。

当在与兔子的连接部分引发异常时,我可以获得该异常,但它会永远重新启动与兔子的连接。

看那个:

    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

系统循环抛出的错误。我知道这是因为 {recconnect:true}。但我希望能够自己捕捉异常。有什么想法吗?

我的脚本的输出是这样的:

Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
Conn Ready
Subscribed queueX
....

【问题讨论】:

    标签: node.js coffeescript rabbitmq amqp node-amqp


    【解决方案1】:

    你可能在某个地方有错误,这可以帮助你

    # 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
    

    【讨论】:

    • 谢谢。这正是我所需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    相关资源
    最近更新 更多