Is there a timeout for acking RabbitMQ messages?

痴心易碎 提交于 2020-01-01 08:38:33

问题


I would like to set a timeout after which a dequeued message is automatically NACKed.

When I dequeue a message I wait until it is transfered over a socket and the other party confirms its reception.

Do I need to keep a list of Timers or can RMQ handle this automatically?

private void Run()
{
    _rmqConnection = _queueConnectionFactory.CreateFactory().CreateConnection();

    _rmqReadchannel = _rmqConnection.CreateModel();

    _rmqReadchannel.QueueDeclare(QueueIdOutgoing(), true, false, false, null);

    _rmqReadchannel.BasicQos(0, 1, false);
    var consumer = new QueueingBasicConsumer(_rmqReadchannel);
    _rmqReadchannel.BasicConsume(QueueIdOutgoing(), false, consumer);
    while (true)
    {
        if (!_rmqReadchannel.IsOpen)
        {
            throw new Exception("Channel is closed");
        }
        var ea = consumer.Queue.Dequeue();
        string jsonData = Encoding.UTF8.GetString(ea.Body);
        if (OnOutgoingMessageReady != null)
        {
            OnOutgoingMessageReady(this, new QueueDataEventArgs(jsonData, ea.DeliveryTag));
        }
        //waiting for ACK from a different thread
    }
}

回答1:


RabbitMQ does not provide any sort of timeout mechanism for acknowledging messages. This is discussed in the official Python tutorial:

There aren't any message timeouts; RabbitMQ will redeliver the message only when the worker connection dies. It's fine even if processing a message takes a very, very long time.

Section 3.1.8 of the AMQP 0-9-1 specification describes Acknowledgements, and is very clear that they can either be Automatic (the client doesn't have to do anything, messages are acknowledged as soon as they are delivered) or Explicit (the client must an Ack for each message or group of messages that it has processed).

Here's some past discussion from back in 2009 confirming that this is the case.

So: yes, if you need a timeout to automatically send NACKs after some interval, you will have to do so yourself.



来源:https://stackoverflow.com/questions/30546977/is-there-a-timeout-for-acking-rabbitmq-messages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!