callback:on(type,[function(){…}])
- type:监听类型
- close,关闭
- error,报错
- blocked,连接失败
- unblocked,连接关闭
info:
- 因为监听本身只是异步行为,async/await模式会梗阻运行,全部只能使用callback
//callback
(async () => {
amqp.connect(url, function (error, connection) {
if (error) throw error;
connection.on('close',()=>{
console.log('通信关闭')
})
connection.on('error',(err)=>{
console.log('报错')
})
connection.on('blocked',()=>{
console.log('通信连接失败')
})
connection.on('unblocked',()=>{
console.log('通信关闭')
})
})
})()