Skip to content

Commit

Permalink
Merge pull request #498 from Particular/warn-not-native
Browse files Browse the repository at this point in the history
Warn not native
  • Loading branch information
WilliamBZA authored Jul 24, 2019
2 parents cf1d3f8 + 58f2256 commit 9808911
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
namespace NServiceBus.AcceptanceTests.NativeTimeouts
{
using System.Linq;
using System.Threading.Tasks;
using AcceptanceTesting;
using EndpointTemplates;
using Features;
using Logging;
using NUnit.Framework;
using Transport.SQLServer;

public class When_configuring_delayed_delivery : NServiceBusAcceptanceTest
{
[Test]
public async Task Should_warn_when_timeoutmanager_is_configured_without_native_delayed_delivery()
{
Requires.MessageDrivenPubSub();

var context = await Scenario.Define<ScenarioContext>()
.WithEndpoint<EndpointWithTimeoutManagerAndNotNative>()
.Done(c => c.EndpointsStarted)
.Run();

Assert.True(context.EndpointsStarted, "because it should not prevent endpoint startup");

var log = context.Logs.Single(l => l.Message.Contains("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`."));
Assert.AreEqual(LogLevel.Warn, log.Level);
}

[Test]
public async Task Should_not_warn_when_timeoutmanager_and_native_delayed_delivery_are_both_configured()
{
Requires.MessageDrivenPubSub();

var context = await Scenario.Define<ScenarioContext>()
.WithEndpoint<EndpointWithTimeoutManagerAndNative>()
.Done(c => c.EndpointsStarted)
.Run();

Assert.True(context.EndpointsStarted, "because it should not prevent endpoint startup");

Assert.IsEmpty(context.Logs.Where(l => l.Message.Contains("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`.")));
}

[Test]
public async Task Should_not_warn_when_only_native_delayed_delivery_is_configured()
{
Requires.MessageDrivenPubSub();

var context = await Scenario.Define<ScenarioContext>()
.WithEndpoint<EndpointWithOnlyNative>()
.Done(c => c.EndpointsStarted)
.Run();

Assert.True(context.EndpointsStarted, "because it should not prevent endpoint startup");

Assert.IsEmpty(context.Logs.Where(l => l.Message.Contains("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`.")));
}

[Test]
public async Task Should_not_warn_when_both_native_delayed_delivery_and_timeoutmanager_is_configured_with_compatibility_disabled()
{
Requires.MessageDrivenPubSub();

var context = await Scenario.Define<ScenarioContext>()
.WithEndpoint<EndpointWithTimeoutManagerAndNativeEnabledButCompatibilityDisabled>()
.Done(c => c.EndpointsStarted)
.Run();

Assert.True(context.EndpointsStarted, "because it should not prevent endpoint startup");

Assert.IsEmpty(context.Logs.Where(l => l.Message.Contains("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`.")));
}

public class EndpointWithTimeoutManagerAndNotNative : EndpointConfigurationBuilder
{
public EndpointWithTimeoutManagerAndNotNative()
{
EndpointSetup<DefaultServer>(config => config.EnableFeature<TimeoutManager>());
}
}

public class EndpointWithTimeoutManagerAndNative : EndpointConfigurationBuilder
{
public EndpointWithTimeoutManagerAndNative()
{
EndpointSetup<DefaultServer>(config =>
{
config.EnableFeature<TimeoutManager>();
config.UseTransport<SqlServerTransport>().UseNativeDelayedDelivery();
});
}
}

public class EndpointWithOnlyNative : EndpointConfigurationBuilder
{
public EndpointWithOnlyNative()
{
EndpointSetup<DefaultServer>(config =>
{
var settings = config.UseTransport<SqlServerTransport>().UseNativeDelayedDelivery();
settings.DisableTimeoutManagerCompatibility();
});
}
}

public class EndpointWithTimeoutManagerAndNativeEnabledButCompatibilityDisabled : EndpointConfigurationBuilder
{
public EndpointWithTimeoutManagerAndNativeEnabledButCompatibilityDisabled()
{
EndpointSetup<DefaultServer>(config =>
{
config.EnableFeature<TimeoutManager>();

var settings = config.UseTransport<SqlServerTransport>().UseNativeDelayedDelivery();
settings.DisableTimeoutManagerCompatibility();
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
namespace NServiceBus.Transport.SQLServer
{
using Features;
using Logging;
using Settings;

static class DelayedDeliveryInfrastructure
{
public static StartupCheckResult CheckForInvalidSettings(SettingsHolder settings)
{
var sendOnlyEndpoint = settings.GetOrDefault<bool>("Endpoint.SendOnly");
if (sendOnlyEndpoint)
var delayedDeliverySettings = settings.GetOrDefault<DelayedDeliverySettings>();
if (delayedDeliverySettings != null)
{
return StartupCheckResult.Failed("Native delayed delivery is only supported for endpoints capable of receiving messages.");
var sendOnlyEndpoint = settings.GetOrDefault<bool>("Endpoint.SendOnly");
if (sendOnlyEndpoint)
{
return StartupCheckResult.Failed("Native delayed delivery is only supported for endpoints capable of receiving messages.");
}
}
else
{
var timeoutManagerEnabled = settings.IsFeatureActive(typeof(TimeoutManager));
if (timeoutManagerEnabled)
{
Logger.Warn("Current configuration of the endpoint uses the TimeoutManager feature for delayed delivery - an option which is not recommended for new deployments. SqlTransport native delayed delivery should be used instead. It can be enabled by calling `UseNativeDelayedDelivery()`.");
}
}

return StartupCheckResult.Success;
}

static ILog Logger = LogManager.GetLogger("DelayedDeliveryInfrastructure");
}
}
10 changes: 1 addition & 9 deletions src/NServiceBus.SqlServer/SqlServerTransportInfrastructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,7 @@ public override TransportSendInfrastructure ConfigureSendInfrastructure()
var dispatcher = new MessageDispatcher(new TableBasedQueueDispatcher(connectionFactory, queueOperationsReader), addressTranslator);
return dispatcher;
},
() =>
{
var result = StartupCheckResult.Success;
if (delayedDeliverySettings != null)
{
result = DelayedDeliveryInfrastructure.CheckForInvalidSettings(settings);
}
return Task.FromResult(result);
});
() => Task.FromResult(DelayedDeliveryInfrastructure.CheckForInvalidSettings(settings)));
}

DelayedMessageTable CreateDelayedMessageTable()
Expand Down

0 comments on commit 9808911

Please sign in to comment.