Skip to content

Commit

Permalink
Merge branch 'hotfix-4.5.7' into support-4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Bussmann committed Oct 7, 2015
2 parents 016af18 + 22ff0d4 commit a4a8621
Showing 1 changed file with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace NServiceBus.Timeout.Hosting.Windows
{
using System;
using System.Transactions;
using Core;
using Features;
using NServiceBus.Pipeline;
using NServiceBus.Settings;
using Satellites;
using Transports;
using Unicast.Transport;
Expand All @@ -17,7 +19,7 @@ public class TimeoutDispatcherProcessor : IAdvancedSatellite
public TimeoutPersisterReceiver TimeoutPersisterReceiver { get; set; }

public PipelineExecutor PipelineExecutor { get; set; }

public Address InputAddress
{
get
Expand Down Expand Up @@ -45,14 +47,26 @@ public bool Handle(TransportMessage message)
return true;
}

try
if (ShouldSuppressTransaction())
{
PipelineExecutor.CurrentContext.Set("do-not-enlist-in-native-transaction", true);
MessageSender.Send(timeoutData.ToTransportMessage(), timeoutData.Destination);
using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
{
try
{
PipelineExecutor.CurrentContext.Set("do-not-enlist-in-native-transaction", true);
MessageSender.Send(timeoutData.ToTransportMessage(), timeoutData.Destination);
}
finally
{
PipelineExecutor.CurrentContext.Set("do-not-enlist-in-native-transaction", false);
}

scope.Complete();
}
}
finally
else
{
PipelineExecutor.CurrentContext.Set("do-not-enlist-in-native-transaction", false);
MessageSender.Send(timeoutData.ToTransportMessage(), timeoutData.Destination);
}

return persisterV2.TryRemove(timeoutId);
Expand Down Expand Up @@ -88,5 +102,22 @@ public Action<TransportReceiver> GetReceiverCustomization()
receiver.FailureManager = new ManageMessageFailuresWithoutSlr(receiver.FailureManager);
};
}

bool ShouldSuppressTransaction()
{
var suppressDtc = SettingsHolder.Get<bool>("Transactions.SuppressDistributedTransactions");
return !IsTransportSupportingDtc() || suppressDtc;
}

bool IsTransportSupportingDtc()
{
var selectedTransport = SettingsHolder.GetOrDefault<TransportDefinition>("NServiceBus.Transport.SelectedTransport");
if (selectedTransport.HasSupportForDistributedTransactions.HasValue)
{
return selectedTransport.HasSupportForDistributedTransactions.Value;
}

return !selectedTransport.GetType().Name.Contains("RabbitMQ");
}
}
}

0 comments on commit a4a8621

Please sign in to comment.