Skip to content

Commit

Permalink
Merge pull request #403 from Particular/use-isolated-dispatch-for-con…
Browse files Browse the repository at this point in the history
…trol-message

Use isolated dispatch for control message to prevent attaching to outbox's transaction scope if transport supports transaction scopes
  • Loading branch information
SzymonPobiega authored Feb 4, 2025
2 parents dfead6c + ad077aa commit 5da2cc5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Extensibility;
using Fakes;
using NServiceBus.Transport;
using NUnit.Framework;

[TestFixture]
Expand Down Expand Up @@ -135,6 +136,7 @@ public async Task Commit_should_send_control_message_and_store_outbox_data()
var controlMessage = dispatched.outgoingMessages.UnicastTransportOperations.Single();
Assert.Multiple(() =>
{
Assert.That(controlMessage.RequiredDispatchConsistency, Is.EqualTo(DispatchConsistency.Isolated));
Assert.That(controlMessage.Message.MessageId, Is.EqualTo(session.SessionId));
Assert.That(controlMessage.Message.Headers[Headers.ControlMessageHeader], Is.EqualTo(bool.TrueString));
Assert.That(controlMessage.Message.Body.IsEmpty, Is.True);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Extensibility;
using Fakes;
using NUnit.Framework;
using Transport;

[TestFixture]
public class TransactionalSessionTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ async Task DispatchControlMessage(CancellationToken cancellationToken)
}
}
var message = new OutgoingMessage(SessionId, headers, ReadOnlyMemory<byte>.Empty);
var outgoingMessages = new TransportOperations(new TransportTransportOperation(message, new UnicastAddressTag(physicalQueueAddress)));
var operation = new TransportTransportOperation(
message,
new UnicastAddressTag(physicalQueueAddress),
null,
DispatchConsistency.Isolated // Avoids promoting to distributed tx by not combining transport and persistence when both share same technology
);
var outgoingMessages = new TransportOperations(operation);
await dispatcher.Dispatch(outgoingMessages, new TransportTransaction(), cancellationToken).ConfigureAwait(false);
}

Expand Down

0 comments on commit 5da2cc5

Please sign in to comment.