mbroadst / qamqp

AMQP 0.9.1 implementation for Qt
Other
151 stars 128 forks source link

Create queues with limit length #30

Closed droidsyer closed 8 years ago

droidsyer commented 8 years ago

Hi, Can I configure a queue with limit of length ? I need to create a queue with last value caching and max number of message equal to 1. I set this policy with a command on rabbitmq server, without effects.... My problem is a queue grow up more than 1 message. Example 1 sender publish a message per second 1 receiver receive a message one per second, but if I break it on a breakpoint then i resume from break, It will receive all message buffered on queue, what I want is receive only last value sent.

I think RabbitMQ server holds ready_messages =0 So doesn't purge oldest messages from queue, saving only last message sent.

Thanks,.

droidsyer commented 8 years ago

I resolved it combining:

QAmqpTable optionTable;
optionTable.insert("x-max-length",1);
queue_->declare(option, optionTable);
void declare(int options = Durable|AutoDelete, const QAmqpTable optionTable = QAmqpTable());
void QAmqpQueue::declare(int options, const QAmqpTable optionTable)
{
    Q_D(QAmqpQueue);
    d->options = options;
    d->optionsTable = optionTable;

    if (!d->opened) {
        d->delayedDeclare = true;
        return;
    }

    d->declare();
}

Added private attribute to QAmqpQueuePrivate class:

private:
    QAmqpTable optionsTable;
mbroadst commented 8 years ago

@droidsyer ah yes, it looks like optional arguments were omitted from both exchange and queue declare methods. Would you be willing to put a PR together for this? Also, just as a nitpick I would prefer that the parameter was called arguments like the spec. Extra bonus points if you put a test together :smile:

droidsyer commented 8 years ago

@mbroadst I've just create a PR about this, it's my first time :-D. Is it right?

droidsyer commented 8 years ago

@mbroadst Can you please be aware about "arguments and qamqpInterface.pri" pull request. It has been tested by me, it works !