async/await:connection.close()
    callback:connection.close([function(err) {…}])

    info:

    • 为什么要使用setTimeout?延迟关闭通道,保证消息队列完成推送
      1. //callback
      2. (async () => {
      3. amqp.connect(url, function (error, connection) {
      4. if (error) throw error;
      5. setTimeout(function () {
      6. connection.close();
      7. process.exit(0);
      8. }, 500);
      9. })
      10. })()
      1. // async/await
      2. (async () => {
      3. try {
      4. const connection = await amqp.connect('url')
      5. setTimeout(async () => {
      6. await connection.close();
      7. process.exit(0);
      8. }, 500)
      9. } catch (e) {
      10. console.log(e)
      11. }
      12. })()