首页 > 解决方案 > 在开玩笑退出时关闭 amqp 连接

问题描述

我有一个看起来类似于这个的笑话测试

const conn = amqplib.connect('amqp_url', {
    timeout: 10 * 1000,
});
describe(`Testing.. `, (case) => {
    test(`Test n`, (done) => {
        conn
            .then(function(conn) {
                return conn.createChannel();
            })
            .then(function(ch) {
                ch.assertQueue('')
                    .then(function(q) {
                        ch.bindQueue(q.queue, case.exchange, case.bKey)
                            .then(() => {
                                ch.consume(q.queue, function(msg) {
                                   //veryfing logic goes here
                                   done();
                                });
                                ch.publish(case.exchange, case.rKey, Buffer.from(case.orgMsg));
                            })
                    });
            })
    });
});


它可以工作,但测试后连接显然没有关闭。

有人可以解释一下在所有测试通过后我应该如何关闭与 amqp 的连接吗?

标签: javascriptnode.jsasynchronousjestjsamqp

解决方案


推荐阅读