Repository navigation
Support & use reject over nack - #116
Merged
Merged
Conversation
Basic.Reject is a core AMQP 0-9-1 method and Constants::BASIC_REJECT was already defined, but no type implemented it, so the library could only send Basic.Nack. Its payload differs from Basic.Nack: there is no `multiple` field, and `requeue` sits at bit 0 of the bitmask rather than bit 1. The tests pin the exact bytes on the way out, and on the way in check that a payload with bit 1 set does not decode as a requeue. Nothing sends this yet. Signed-off-by: Freddie Lamble <flamble1@bloomberg.net>
A consumer could only resolve a delivery with basic.ack or basic.nack. Add the two basic.reject outcomes so the layers above can ask for a counted negative acknowledgement, and give every outcome a name that says which AMQP method it sends. The existing REJECT and REQUEUE predate support for basic.reject. Both send basic.nack, so REJECT in particular reads as the opposite of what it does, and it would now sit beside REJECT_REQUEUE_FALSE, which really does send basic.reject. NACK_REQUEUE_FALSE and NACK_REQUEUE_TRUE become the canonical spellings and the old names remain as deprecated aliases of the same values, so existing callers keep compiling. All five values are written out, since the values are the stable part, and BSLMF_ASSERT pins each deprecated name to the value it has always had. Two predicates, which answer different questions: usesBasicReject(Type) reports which AMQP method a value sends, for the layer that has to pick a callback. It is deliberately not called isReject, which would return false for REJECT and read as a bug. supportsMultiple(Type) reports whether that method carries a `multiple` field, for the layer that batches. basic.ack and basic.nack carry one, basic.reject does not, so a reject can never be batched: doing so would resolve only the highest delivery tag and leave the rest outstanding. The enum had no test of its own and the new operator<< none either, so add rmqt_consumerack.t.cpp. https://www.rabbitmq.com/docs/nack https://www.rabbitmq.com/docs/quorum-queues#when-is-delivery-count-incremented Signed-off-by: Freddie Lamble <flamble1@bloomberg.net>
Consumers could only return a failed message with nack(). From RabbitMQ 4.3 a quorum queue's delivery-limit is measured against delivery-count, which Basic.Nack does not increment, so a message returned with nack(true) is redelivered without ever reaching the limit. https://www.rabbitmq.com/docs/nack https://www.rabbitmq.com/docs/quorum-queues#when-is-delivery-count-incremented Add reject(requeue) to rmqp::MessageGuard and rmqa::MessageGuard, and sendReject() to ReceiveChannel. reject() is pure virtual on the interface, matching every other method on it, so an out-of-tree implementation of rmqp::MessageGuard will need updating. The gmock in rmqtestmocks is updated here. MultipleAckHandler must not batch rejects, as Basic.Reject has no `multiple` field, so it gates batching on ConsumerAck::supportsMultiple() and rejects are sent one delivery at a time. Batching one would have resolved only the highest tag in the batch and left the rest outstanding. Nothing changes for an existing caller. nack() still sends Basic.Nack, and a guard destroyed without being resolved still nacks with requeue; that is changed separately at the end of the series. Signed-off-by: Freddie Lamble <flamble1@bloomberg.net>
Publish one consumer_message_handled count per resolved delivery, tagged rmqResult with ack, nack_requeue_true, nack_requeue_false, reject_requeue_true or reject_requeue_false. Once the unresolved path rejects, any nack_* in the data is an explicit application call, so this shows which applications still return failures with Basic.Nack. The counter is published from the loop which filters resolutions for a stale channel generation, so a resolution dropped because the channel was reset is not counted. ReceiveChannel holds the tag vectors, one per ConsumerAck::Type, and the metric name, all built once in the constructor. This runs per message on the event loop thread, so it allocates nothing: the alternative copies the vhost tags and builds three strings for every delivery resolved. Channel already keeps a derived d_vhostAndChannelTags the same way. Document reject alongside nack in the doxygen guide, and switch the README consumer callback to it. The two example edits are comments in producer examples, which refer to resolving the message that triggered the publish. Signed-off-by: Freddie Lamble <flamble1@bloomberg.net>
A MessageGuard destroyed without having been resolved now rejects with requeue instead of nacking. An unresolved guard almost always means an exception unwound through the consumer callback, which is a failed delivery attempt and should be counted as one. From RabbitMQ 4.3 only Basic.Reject increments delivery-count, so only a reject is bounded by a quorum queue's delivery-limit. An explicit nack() is never turned into a reject. An application that asks for an uncounted return still gets one. This is the only behaviour change in the series. Every commit before it makes reject() available without altering what an existing consumer sends to the broker. Signed-off-by: Freddie Lamble <flamble1@bloomberg.net>
michalovits
approved these changes
Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the rmqamqpt::BasicReject wire type
Basic.Reject is a core AMQP 0-9-1 method and Constants::BASIC_REJECT was
already defined, but no type implemented it, so the library could only
send Basic.Nack.
Its payload differs from Basic.Nack: there is no
multiplefield, andrequeuesits at bit 0 of the bitmask rather than bit 1. The tests pinthe exact bytes on the way out, and on the way in check that a payload
with bit 1 set does not decode as a requeue.
Nothing sends this yet.
Add reject outcomes to rmqt::ConsumerAck
A consumer could only resolve a delivery with basic.ack or basic.nack.
Add the two basic.reject outcomes so the layers above can ask for a
counted negative acknowledgement, and give every outcome a name that
says which AMQP method it sends.
The existing REJECT and REQUEUE predate support for basic.reject. Both
send basic.nack, so REJECT in particular reads as the opposite of what
it does, and it would now sit beside REJECT_REQUEUE_FALSE, which really
does send basic.reject. NACK_REQUEUE_FALSE and NACK_REQUEUE_TRUE become
the canonical spellings and the old names remain as deprecated aliases
of the same values, so existing callers keep compiling. All five values
are written out, since the values are the stable part, and BSLMF_ASSERT
pins each deprecated name to the value it has always had.
Two predicates, which answer different questions:
usesBasicReject(Type) reports which AMQP method a value sends, for the
layer that has to pick a callback. It is deliberately not called
isReject, which would return false for REJECT and read as a bug.
supportsMultiple(Type) reports whether that method carries a
multiplefield, for the layer that batches. basic.ack and basic.nack carry one,
basic.reject does not, so a reject can never be batched: doing so would
resolve only the highest delivery tag and leave the rest outstanding.
The enum had no test of its own and the new operator<< none either, so
add rmqt_consumerack.t.cpp.
https://www.rabbitmq.com/docs/nack
https://www.rabbitmq.com/docs/quorum-queues#when-is-delivery-count-incremented
Add MessageGuard::reject()
Consumers could only return a failed message with nack(). From RabbitMQ
4.3 a quorum queue's delivery-limit is measured against delivery-count,
which Basic.Nack does not increment, so a message returned with
nack(true) is redelivered without ever reaching the limit.
https://www.rabbitmq.com/docs/nack
https://www.rabbitmq.com/docs/quorum-queues#when-is-delivery-count-incremented
Add reject(requeue) to rmqp::MessageGuard and rmqa::MessageGuard, and
sendReject() to ReceiveChannel. reject() is pure virtual on the
interface, matching every other method on it, so an out-of-tree
implementation of rmqp::MessageGuard will need updating. The gmock in
rmqtestmocks is updated here.
MultipleAckHandler must not batch rejects, as Basic.Reject has no
multiplefield, so it gates batching on ConsumerAck::supportsMultiple()and rejects are sent one delivery at a time. Batching one would have
resolved only the highest tag in the batch and left the rest
outstanding.
Nothing changes for an existing caller. nack() still sends Basic.Nack,
and a guard destroyed without being resolved still nacks with requeue;
that is changed separately at the end of the series.
Add the consumer_message_handled metric, and document reject
Publish one consumer_message_handled count per resolved delivery,
tagged rmqResult with ack, nack_requeue_true, nack_requeue_false,
reject_requeue_true or reject_requeue_false. Once the unresolved path
rejects, any nack_* in the data is an explicit application call, so
this shows which applications still return failures with Basic.Nack.
The counter is published from the loop which filters resolutions for a
stale channel generation, so a resolution dropped because the channel
was reset is not counted.
ReceiveChannel holds the tag vectors, one per ConsumerAck::Type, and the
metric name, all built once in the constructor. This runs per message on
the event loop thread, so it allocates nothing: the alternative copies
the vhost tags and builds three strings for every delivery resolved.
Channel already keeps a derived d_vhostAndChannelTags the same way.
Document reject alongside nack in the doxygen guide, and switch the
README consumer callback to it. The two example edits are comments in
producer examples, which refer to resolving the message that triggered
the publish.
Reject, rather than nack, an unresolved message
A MessageGuard destroyed without having been resolved now rejects with
requeue instead of nacking. An unresolved guard almost always means an
exception unwound through the consumer callback, which is a failed
delivery attempt and should be counted as one. From RabbitMQ 4.3 only
Basic.Reject increments delivery-count, so only a reject is bounded by
a quorum queue's delivery-limit.
An explicit nack() is never turned into a reject. An application that
asks for an uncounted return still gets one.
This is the only behaviour change in the series. Every commit before it
makes reject() available without altering what an existing consumer
sends to the broker.