Skip to content

Commit c642f7b

Browse files
authored
Merge pull request #1710 from rabbitmq/lukebakken/only-add-pub-seq-no-if-tracking-enabled
Only add `x-dotnet-pub-seq-no` when tracking enabled
2 parents af007e1 + e7f1b3f commit c642f7b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

projects/RabbitMQ.Client/CreateChannelOptions.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System.Threading.RateLimiting;
33-
using RabbitMQ.Client.Impl;
3433

3534
namespace RabbitMQ.Client
3635
{
@@ -41,11 +40,24 @@ public sealed class CreateChannelOptions
4140
{
4241
/// <summary>
4342
/// Enable or disable publisher confirmations on this channel. Defaults to <c>false</c>
43+
///
44+
/// Note that, if this is enabled, and <see cref="PublisherConfirmationTrackingEnabled"/> is <b>not</b>
45+
/// enabled, the broker may send a <c>basic.return</c> response if a message is published with <c>mandatory: true</c>
46+
/// and the broker can't route the message. This response will not, however, contain the publish sequence number
47+
/// for the message, so it is difficult to correlate the response to the correct message. Users of this library
48+
/// could add the <see cref="Constants.PublishSequenceNumberHeader"/> header with the value returned by
49+
/// <see cref="IChannel.GetNextPublishSequenceNumberAsync(System.Threading.CancellationToken)"/> to allow correlation
50+
/// of the response with the correct message.
4451
/// </summary>
4552
public bool PublisherConfirmationsEnabled { get; set; } = false;
4653

4754
/// <summary>
4855
/// Should this library track publisher confirmations for you? Defaults to <c>false</c>
56+
///
57+
/// When enabled, the <see cref="Constants.PublishSequenceNumberHeader" /> header will be
58+
/// added to every published message, and will contain the message's publish sequence number.
59+
/// If the broker then sends a <c>basic.return</c> response for the message, this library can
60+
/// then correctly handle the message.
4961
/// </summary>
5062
public bool PublisherConfirmationTrackingEnabled { get; set; } = false;
5163

projects/RabbitMQ.Client/Impl/Channel.BasicPublish.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void MaybeAddActivityToHeaders(IDictionary<string, object?> headers,
215215

216216
void MaybeAddPublishSequenceNumberToHeaders(IDictionary<string, object?> headers)
217217
{
218-
if (_publisherConfirmationsEnabled)
218+
if (_publisherConfirmationsEnabled && _publisherConfirmationTrackingEnabled)
219219
{
220220
byte[] publishSequenceNumberBytes = new byte[8];
221221
NetworkOrderSerializer.WriteUInt64(ref publishSequenceNumberBytes.GetStart(), publishSequenceNumber);

projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private void HandleNack(ulong deliveryTag, bool multiple, bool isReturn)
228228
[MethodImpl(MethodImplOptions.AggressiveInlining)]
229229
private void HandleReturn(BasicReturnEventArgs basicReturnEvent)
230230
{
231-
if (_publisherConfirmationsEnabled)
231+
if (_publisherConfirmationsEnabled && _publisherConfirmationTrackingEnabled)
232232
{
233233
ulong publishSequenceNumber = 0;
234234
IReadOnlyBasicProperties props = basicReturnEvent.BasicProperties;

0 commit comments

Comments
 (0)