0

amqplib在 nodejs 应用程序中使用。前端有一些繁重的处理会导致接收rabbitmq消息时出现一些延迟。当使用 监控我的队列时rabbitmqctl list_queues,等待处理的消息数量永远不会停止攀升。

有没有办法设置我的频道以便在队列有给定数量的消息等待时丢弃消息?

以下是我设置频道的方式:

amqp.connect('amqp://localhost')
    .then(conn => {
        return conn.createChannel();
    })
    .then(channel => {
        channel.assertQueue(q, {durable: false, autoDelete: true});
        channel.prefetch(1);
        channel.bindQueue(q.queue, topic, 'myroutingkey');

        return channel.consume(q, (msg) => {
            mycallback(channel, msg);
        });
    })
    .then(() => {})
    .catch(err => {});
4

1 回答 1

0

感谢 Jørgen 指向 rabbitmq 文档的指针,我在 amqplib 文档中找到了等价物,我可以通过添加maxLength: 1到我的队列设置来强制删除行为

channel.assertQueue(q, {durable: false, autoDelete: true, maxLength: 1});
于 2018-02-05T13:51:59.537 回答