Skip to content

Implement PreSettled consumer feature#143

Merged
Gsantomaggio merged 3 commits intomainfrom
feat/consumer_presettled
Jan 26, 2026
Merged

Implement PreSettled consumer feature#143
Gsantomaggio merged 3 commits intomainfrom
feat/consumer_presettled

Conversation

@Gsantomaggio
Copy link
Member

@Gsantomaggio Gsantomaggio commented Jan 23, 2026

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

closes: #142

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PreSettledDeliveryContext class 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:
  1. Passing the nativeMessage to PreSettledDeliveryContext and disposing it immediately after construction (since pre-settled messages don't need further settlement operations)
  2. Explicitly disposing the nativeMessage after passing it to the message handler when PreSettled mode is enabled
  3. 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>
@Gsantomaggio Gsantomaggio marked this pull request as ready for review January 26, 2026 12:18
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
@Gsantomaggio Gsantomaggio added this to the 0.6.0 milestone Jan 26, 2026
@Gsantomaggio Gsantomaggio self-assigned this Jan 26, 2026
@Gsantomaggio Gsantomaggio added the enhancement New feature or request label Jan 26, 2026
@Gsantomaggio Gsantomaggio merged commit 4a9f27b into main Jan 26, 2026
3 of 4 checks passed
@Gsantomaggio Gsantomaggio deleted the feat/consumer_presettled branch January 26, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pre-settled option to consumer builder

1 participant

Comments