Implement PreSettled consumer feature#143
Merged
Gsantomaggio merged 3 commits intomainfrom Jan 26, 2026
Merged
Conversation
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements a PreSettled consumer feature that allows messages to be automatically settled by the broker, eliminating the need for explicit settlement operations by the consumer. The feature uses AMQP 1.0's ReceiverSettleMode.Second with SenderSettleMode.Settled to achieve pre-settled delivery.
Changes:
- Added
PreSettled(bool)method to consumer builder API for configuring pre-settled mode - Created
PreSettledDeliveryContextclass that throws exceptions when settlement operations are attempted - Modified consumer implementation to use PreSettledDeliveryContext when pre-settled mode is enabled and skip unsettled message counter increments
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Consumer/PreSettledConsumerTests.cs | Comprehensive test suite covering pre-settled consumer behavior, error cases, and message counter validation |
| RabbitMQ.AMQP.Client/PublicAPI.Unshipped.txt | API surface updates for new PreSettled method and PreSettledDeliveryContext class |
| RabbitMQ.AMQP.Client/Utils.cs | Enhanced CreateAttach to support preSettled parameter with ReceiverSettleMode.Second; minor formatting improvements |
| RabbitMQ.AMQP.Client/Impl/DeliveryContext.cs | New PreSettledDeliveryContext class implementing IContext with methods that throw InvalidOperationException |
| RabbitMQ.AMQP.Client/Impl/AmqpConsumerBuilder.cs | Added PreSettled configuration property and builder method |
| RabbitMQ.AMQP.Client/Impl/AmqpConsumer.cs | Logic to create PreSettledDeliveryContext based on configuration and skip counter increments |
| RabbitMQ.AMQP.Client/IConsumerBuilder.cs | Public interface addition for PreSettled method with documentation |
Comments suppressed due to low confidence (1)
RabbitMQ.AMQP.Client/Impl/AmqpConsumer.cs:199
- In the PreSettled mode, the nativeMessage object is never explicitly disposed. In the non-PreSettled case, DeliveryContext disposes the message in the finally blocks of Accept(), Discard(), and Requeue() methods. However, PreSettledDeliveryContext doesn't have access to the nativeMessage, so it cannot dispose of it. Consider either:
- Passing the nativeMessage to PreSettledDeliveryContext and disposing it immediately after construction (since pre-settled messages don't need further settlement operations)
- Explicitly disposing the nativeMessage after passing it to the message handler when PreSettled mode is enabled
- Verifying that the AMQP library or receiver link automatically handles disposal of pre-settled messages and documenting this behavior
This could potentially lead to resource leaks in high-throughput scenarios if the native Message objects are not garbage collected promptly.
IContext context = _configuration.PreSettled switch
{
true => new PreSettledDeliveryContext(),
false => new DeliveryContext(_receiverLink, nativeMessage, _unsettledMessageCounter,
_metricsReporter)
};
if (!_configuration.PreSettled)
{
_unsettledMessageCounter.Increment();
}
var amqpMessage = new AmqpMessage(nativeMessage);
// TODO catch exceptions thrown by handlers,
// then call exception handler?
if (_configuration.Handler is not null)
{
await _configuration.Handler(context, amqpMessage)
.ConfigureAwait(false);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
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.
This PR implements a PreSettled consumer feature that allows messages to be automatically settled by the broker, eliminating the need for explicit settlement operations by the consumer. The feature uses AMQP 1.0's ReceiverSettleMode.Second with SenderSettleMode.Settled to achieve pre-settled delivery.
Changes:
PreSettled(bool)method to consumer builder API for configuring pre-settled modePreSettledDeliveryContextclass that throws exceptions when settlement operations are attemptedcloses: #142