Skip to content

Only add x-dotnet-pub-seq-no when tracking enabled #1710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion projects/RabbitMQ.Client/CreateChannelOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
//---------------------------------------------------------------------------

using System.Threading.RateLimiting;
using RabbitMQ.Client.Impl;

namespace RabbitMQ.Client
{
Expand All @@ -41,11 +40,24 @@ public sealed class CreateChannelOptions
{
/// <summary>
/// Enable or disable publisher confirmations on this channel. Defaults to <c>false</c>
///
/// Note that, if this is enabled, and <see cref="PublisherConfirmationTrackingEnabled"/> is <b>not</b>
/// enabled, the broker may send a <c>basic.return</c> response if a message is published with <c>mandatory: true</c>
/// 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 <see cref="Constants.PublishSequenceNumberHeader"/> header with the value returned by
/// <see cref="IChannel.GetNextPublishSequenceNumberAsync(System.Threading.CancellationToken)"/> to allow correlation
/// of the response with the correct message.
/// </summary>
public bool PublisherConfirmationsEnabled { get; set; } = false;

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

Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/Channel.BasicPublish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void MaybeAddActivityToHeaders(IDictionary<string, object?> headers,

void MaybeAddPublishSequenceNumberToHeaders(IDictionary<string, object?> headers)
{
if (_publisherConfirmationsEnabled)
if (_publisherConfirmationsEnabled && _publisherConfirmationTrackingEnabled)
{
byte[] publishSequenceNumberBytes = new byte[8];
NetworkOrderSerializer.WriteUInt64(ref publishSequenceNumberBytes.GetStart(), publishSequenceNumber);
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down