Skip to content

Support & use reject over nack - #116

Merged
flamble merged 5 commits into
bloomberg:mainfrom
flamble:use-reject
Nov 19, 2026
Merged

flamble merged 5 commits into
bloomberg:mainfrom
flamble:use-reject

Conversation

@flamble

@flamble flamble commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

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 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.

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 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

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
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.

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.

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>
@flamble
flamble merged commit f9c885b into bloomberg:main Nov 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants