【问题标题】:Can one drop rabbitmq messages when queues are too large using amqplib in nodejs?当队列太大时,可以在 nodejs 中使用 amqplib 丢弃rabbitmq 消息吗?
【发布时间】:2018-02-05 21:51:59
【问题描述】:

我在 nodejs 应用程序中使用amqplib。前端有一些繁重的处理会导致接收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 => {});

【问题讨论】:

标签: node.js rabbitmq amqp node-amqplib


【解决方案1】:

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

channel.assertQueue(q, {durable: false, autoDelete: true, maxLength: 1});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    相关资源
    最近更新 更多