Skip to content

Commit

Permalink
enforcing transaction isolation level on peeks (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmasternak authored and Marcin Hoppe committed Oct 7, 2016
1 parent 7f1645d commit d75fb52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Data.SqlClient;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using Logging;

class LegacyQueuePeeker : IPeekMessagesInQueue
Expand All @@ -20,6 +21,7 @@ public async Task<int> Peek(TableBasedQueue inputQueue, RepeatedFailuresOverTime

try
{
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions {IsolationLevel = IsolationLevel.ReadCommitted}, TransactionScopeAsyncFlowOption.Enabled))
using (var connection = await connectionFactory.OpenNewConnection(inputQueue.TransportAddress).ConfigureAwait(false))
{
messageCount = await inputQueue.TryPeek(connection, cancellationToken).ConfigureAwait(false);
Expand All @@ -32,6 +34,8 @@ public async Task<int> Peek(TableBasedQueue inputQueue, RepeatedFailuresOverTime

await Task.Delay(settings.Delay, cancellationToken).ConfigureAwait(false);
}

scope.Complete();
}
}
catch (OperationCanceledException)
Expand Down
4 changes: 4 additions & 0 deletions src/NServiceBus.SqlServer/Receiving/QueuePeeker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Data.SqlClient;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using Logging;

class QueuePeeker : IPeekMessagesInQueue
Expand All @@ -20,6 +21,7 @@ public async Task<int> Peek(TableBasedQueue inputQueue, RepeatedFailuresOverTime

try
{
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions {IsolationLevel = IsolationLevel.ReadCommitted}, TransactionScopeAsyncFlowOption.Enabled))
using (var connection = await connectionFactory.OpenNewConnection().ConfigureAwait(false))
{
messageCount = await inputQueue.TryPeek(connection, cancellationToken).ConfigureAwait(false);
Expand All @@ -32,6 +34,8 @@ public async Task<int> Peek(TableBasedQueue inputQueue, RepeatedFailuresOverTime

await Task.Delay(settings.Delay, cancellationToken).ConfigureAwait(false);
}

scope.Complete();
}
}
catch (OperationCanceledException)
Expand Down

0 comments on commit d75fb52

Please sign in to comment.