From d051f5a445f69ca9def04ebd88c75b4c4123160b Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Sun, 1 Feb 2015 09:49:39 -0500 Subject: [PATCH] add support for Basic.Reject This adds the reject method to QAmqpQueue in order to reject an incoming message, and conditionally requeue it. --- src/qamqpqueue.cpp | 26 ++++++++++++++++++++++++++ src/qamqpqueue.h | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/qamqpqueue.cpp b/src/qamqpqueue.cpp index 29b41fb..9d9b4b8 100644 --- a/src/qamqpqueue.cpp +++ b/src/qamqpqueue.cpp @@ -533,6 +533,32 @@ void QAmqpQueue::ack(qlonglong deliveryTag, bool multiple) d->sendFrame(frame); } +void QAmqpQueue::reject(const QAmqpMessage &message, bool requeue) +{ + ack(message.deliveryTag(), requeue); +} + +void QAmqpQueue::reject(qlonglong deliveryTag, bool requeue) +{ + Q_D(QAmqpQueue); + if (!d->opened) { + qAmqpDebug() << Q_FUNC_INFO << "channel is not open"; + return; + } + + QAmqpMethodFrame frame(QAmqpFrame::Basic, QAmqpQueuePrivate::bmReject); + frame.setChannel(d->channelNumber); + + QByteArray arguments; + QDataStream out(&arguments, QIODevice::WriteOnly); + + out << deliveryTag; + out << qint8(requeue ? 1 : 0); + + frame.setArguments(arguments); + d->sendFrame(frame); +} + bool QAmqpQueue::cancel(bool noWait) { Q_D(QAmqpQueue); diff --git a/src/qamqpqueue.h b/src/qamqpqueue.h index aa873f7..17d668c 100644 --- a/src/qamqpqueue.h +++ b/src/qamqpqueue.h @@ -70,9 +70,10 @@ public: bool consume(int options = NoOptions); void get(bool noAck = true); bool cancel(bool noWait = false); - void ack(const QAmqpMessage &message); void ack(qlonglong deliveryTag, bool multiple); + void reject(const QAmqpMessage &message, bool requeue); + void reject(qlonglong deliveryTag, bool requeue); Q_SIGNALS: void declared();