callback:on(type,[function(){…}])

    • type:监听类型
      • close,关闭
      • error,报错
      • blocked,连接失败
      • unblocked,连接关闭

    info:

    • 因为监听本身只是异步行为,async/await模式会梗阻运行,全部只能使用callback
      1. //callback
      2. (async () => {
      3. amqp.connect(url, function (error, connection) {
      4. if (error) throw error;
      5. connection.on('close',()=>{
      6. console.log('通信关闭')
      7. })
      8. connection.on('error',(err)=>{
      9. console.log('报错')
      10. })
      11. connection.on('blocked',()=>{
      12. console.log('通信连接失败')
      13. })
      14. connection.on('unblocked',()=>{
      15. console.log('通信关闭')
      16. })
      17. })
      18. })()