await/async:Channel#close()
    callback:Channel#close([function(err) {…}])

    1. // await/async
    2. try {
    3. const connection = await amqp.connect(url)
    4. const channel = await connection.createChannel();
    5. const queue = 'hello';
    6. const msg = 'Hello World!';
    7. await channel.assertQueue(queue, { durable: false });
    8. await channel.sendToQueue(queue, Buffer.from(msg));
    9. console.log(" [x] Sent %s", msg);
    10. await channel.close();
    11. setTimeout(async () => await connection.close(), 500)
    12. } catch (e) {
    13. console.log(e)
    14. }
    1. // callback
    2. (async () => {
    3. amqp.connect(url, function (error, connection) {
    4. if (error) throw error;
    5. connection.createChannel((error1, channel) => {
    6. if (error1) throw error1;
    7. const queue = 'hello';
    8. const msg = 'Hello World!';
    9. channel.assertQueue(queue, {
    10. durable: false
    11. });
    12. channel.sendToQueue(queue, Buffer.from(msg));
    13. console.log(" [x] Sent %s", msg);
    14. channel.close();
    15. setTimeout(function () {
    16. connection.close();
    17. process.exit(0);
    18. }, 500);
    19. });
    20. })
    21. })()