diff --git a/projects/RabbitMQ.Client/CreateChannelOptions.cs b/projects/RabbitMQ.Client/CreateChannelOptions.cs index 982316a05..3ffaa065b 100644 --- a/projects/RabbitMQ.Client/CreateChannelOptions.cs +++ b/projects/RabbitMQ.Client/CreateChannelOptions.cs @@ -30,7 +30,6 @@ //--------------------------------------------------------------------------- using System.Threading.RateLimiting; -using RabbitMQ.Client.Impl; namespace RabbitMQ.Client { @@ -41,11 +40,24 @@ public sealed class CreateChannelOptions { /// /// Enable or disable publisher confirmations on this channel. Defaults to false + /// + /// Note that, if this is enabled, and is not + /// enabled, the broker may send a basic.return response if a message is published with mandatory: true + /// and the broker can't route the message. This response will not, however, contain the publish sequence number + /// for the message, so it is difficult to correlate the response to the correct message. Users of this library + /// could add the header with the value returned by + /// to allow correlation + /// of the response with the correct message. /// public bool PublisherConfirmationsEnabled { get; set; } = false; /// /// Should this library track publisher confirmations for you? Defaults to false + /// + /// When enabled, the header will be + /// added to every published message, and will contain the message's publish sequence number. + /// If the broker then sends a basic.return response for the message, this library can + /// then correctly handle the message. /// public bool PublisherConfirmationTrackingEnabled { get; set; } = false; diff --git a/projects/RabbitMQ.Client/Impl/Channel.BasicPublish.cs b/projects/RabbitMQ.Client/Impl/Channel.BasicPublish.cs index 04744cb0e..b7ded1397 100644 --- a/projects/RabbitMQ.Client/Impl/Channel.BasicPublish.cs +++ b/projects/RabbitMQ.Client/Impl/Channel.BasicPublish.cs @@ -215,7 +215,7 @@ void MaybeAddActivityToHeaders(IDictionary headers, void MaybeAddPublishSequenceNumberToHeaders(IDictionary headers) { - if (_publisherConfirmationsEnabled) + if (_publisherConfirmationsEnabled && _publisherConfirmationTrackingEnabled) { byte[] publishSequenceNumberBytes = new byte[8]; NetworkOrderSerializer.WriteUInt64(ref publishSequenceNumberBytes.GetStart(), publishSequenceNumber); diff --git a/projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs b/projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs index 2ba8e0524..d179af7aa 100644 --- a/projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs +++ b/projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs @@ -228,7 +228,7 @@ private void HandleNack(ulong deliveryTag, bool multiple, bool isReturn) [MethodImpl(MethodImplOptions.AggressiveInlining)] private void HandleReturn(BasicReturnEventArgs basicReturnEvent) { - if (_publisherConfirmationsEnabled) + if (_publisherConfirmationsEnabled && _publisherConfirmationTrackingEnabled) { ulong publishSequenceNumber = 0; IReadOnlyBasicProperties props = basicReturnEvent.BasicProperties;