Skip to content

Commit

Permalink
Merge branch 'release-2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasohlund committed Sep 25, 2014
2 parents 3f8f3c0 + 9e76275 commit 781c1eb
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 118 deletions.
2 changes: 1 addition & 1 deletion src/NServiceBus.SqlServer/NServiceBus.SqlServer.csproj
Expand Up @@ -71,8 +71,8 @@
<Compile Include="SecondaryReceiveSettings.cs" />
<Compile Include="SqlServerSettingsExtensions.cs" />
<Compile Include="SqlServerStorageContext.cs" />
<Compile Include="SqlServer.cs" />
<Compile Include="SqlServerTransport.cs" />
<Compile Include="SqlServerTransportFeature.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="SqlServerPollingDequeueStrategy.cs" />
<Compile Include="SqlServerMessageSender.cs" />
Expand Down
29 changes: 0 additions & 29 deletions src/NServiceBus.SqlServer/SqlServer.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/NServiceBus.SqlServer/SqlServerSettingsExtensions.cs
Expand Up @@ -15,7 +15,7 @@ public static class SqlServerSettingsExtensions
/// <returns></returns>
public static TransportExtensions<SqlServerTransport> DisableCallbackReceiver(this TransportExtensions<SqlServerTransport> transportExtensions)
{
transportExtensions.GetSettings().Set(Features.SqlServerTransport.UseCallbackReceiverSettingKey, false);
transportExtensions.GetSettings().Set(Features.SqlServerTransportFeature.UseCallbackReceiverSettingKey, false);
return transportExtensions;
}

Expand All @@ -32,7 +32,7 @@ public static TransportExtensions<SqlServerTransport> CallbackReceiverMaxConcurr
{
throw new ArgumentException("Maximum concurrency value must be greater than zero.","maxConcurrency");
}
transportExtensions.GetSettings().Set(Features.SqlServerTransport.MaxConcurrencyForCallbackReceiverSettingKey, maxConcurrency);
transportExtensions.GetSettings().Set(Features.SqlServerTransportFeature.MaxConcurrencyForCallbackReceiverSettingKey, maxConcurrency);
return transportExtensions;
}
}
Expand Down
104 changes: 18 additions & 86 deletions src/NServiceBus.SqlServer/SqlServerTransport.cs
@@ -1,100 +1,32 @@
namespace NServiceBus.Features
namespace NServiceBus
{
using System;
using System.Linq;
using Pipeline;
using Settings;
using Support;
using Configuration.AdvanceExtensibility;
using Features;
using Transports;
using Transports.SQLServer;
using System.Configuration;

/// <summary>
/// Configures NServiceBus to use SqlServer as the default transport
/// SqlServer Transport
/// </summary>
class SqlServerTransport : ConfigureTransport
public class SqlServerTransport : TransportDefinition
{
public const string UseCallbackReceiverSettingKey = "SqlServer.UseCallbackReceiver";
public const string MaxConcurrencyForCallbackReceiverSettingKey = "SqlServer.MaxConcurrencyForCallbackReceiver";

/// <summary>
/// Ctor
/// </summary>
public SqlServerTransport()
{
Defaults(s =>
{
s.SetDefault(UseCallbackReceiverSettingKey, true);
s.SetDefault(MaxConcurrencyForCallbackReceiverSettingKey, 1);
});
}

protected override string ExampleConnectionStringForErrorMessage
{
get { return @"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True"; }
}

protected override string GetLocalAddress(ReadOnlySettings settings)
{
return settings.EndpointName();
RequireOutboxConsent = true;
}

protected override void Configure(FeatureConfigurationContext context, string connectionString)
/// <summary>
/// Gives implementations access to the <see cref="T:NServiceBus.BusConfiguration"/> instance at configuration time.
/// </summary>
protected override void Configure(BusConfiguration config)
{
//Until we refactor the whole address system
Address.IgnoreMachineName();

var useCallbackReceiver = context.Settings.Get<bool>(UseCallbackReceiverSettingKey);
var maxConcurrencyForCallbackReceiver = context.Settings.Get<int>(MaxConcurrencyForCallbackReceiverSettingKey);

var queueName = GetLocalAddress(context.Settings);
var callbackQueue = string.Format("{0}.{1}", queueName, RuntimeEnvironment.MachineName);

//Load all connectionstrings
var collection =
ConfigurationManager
.ConnectionStrings
.Cast<ConnectionStringSettings>()
.Where(x => x.Name.StartsWith("NServiceBus/Transport/"))
.ToDictionary(x => x.Name.Replace("NServiceBus/Transport/", String.Empty), y => y.ConnectionString);

if (String.IsNullOrEmpty(connectionString))
{
throw new ArgumentException("Sql Transport connection string cannot be empty or null.");
}

var container = context.Container;

container.ConfigureComponent<SqlServerQueueCreator>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.ConnectionString, connectionString);

container.ConfigureComponent<SqlServerMessageSender>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.DefaultConnectionString, connectionString)
.ConfigureProperty(p => p.ConnectionStringCollection, collection)
.ConfigureProperty(p => p.CallbackQueue, callbackQueue);

container.ConfigureComponent<SqlServerPollingDequeueStrategy>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.ConnectionString, connectionString);

context.Container.ConfigureComponent(b => new SqlServerStorageContext(b.Build<PipelineExecutor>(), connectionString), DependencyLifecycle.InstancePerUnitOfWork);

if (useCallbackReceiver)
{
var callbackAddress = Address.Parse(callbackQueue);

context.Container.ConfigureComponent<CallbackQueueCreator>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.Enabled, true)
.ConfigureProperty(p => p.CallbackQueueAddress, callbackAddress);

context.Pipeline.Register<PromoteCallbackQueueBehavior.Registration>();
}
context.Container.RegisterSingleton(new SecondaryReceiveConfiguration(workQueue =>
{
//if this isn't the main queue we shouldn't use callback receiver
if (!useCallbackReceiver || workQueue != queueName)
{
return SecondaryReceiveSettings.Disabled();
}
return SecondaryReceiveSettings.Enabled(callbackQueue, maxConcurrencyForCallbackReceiver);
}));
config.EnableFeature<SqlServerTransportFeature>();
config.EnableFeature<MessageDrivenSubscriptions>();
config.EnableFeature<TimeoutManagerBasedDeferral>();
config.GetSettings().EnableFeatureByDefault<StorageDrivenPublishing>();
config.GetSettings().EnableFeatureByDefault<TimeoutManager>();
}
}
}
97 changes: 97 additions & 0 deletions src/NServiceBus.SqlServer/SqlServerTransportFeature.cs
@@ -0,0 +1,97 @@
namespace NServiceBus.Features
{
using System;
using System.Linq;
using Pipeline;
using Settings;
using Support;
using Transports;
using Transports.SQLServer;
using System.Configuration;

class SqlServerTransportFeature : ConfigureTransport
{
public const string UseCallbackReceiverSettingKey = "SqlServer.UseCallbackReceiver";
public const string MaxConcurrencyForCallbackReceiverSettingKey = "SqlServer.MaxConcurrencyForCallbackReceiver";

public SqlServerTransportFeature()
{
Defaults(s =>
{
s.SetDefault(UseCallbackReceiverSettingKey, true);
s.SetDefault(MaxConcurrencyForCallbackReceiverSettingKey, 1);
});
}

protected override string ExampleConnectionStringForErrorMessage
{
get { return @"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True"; }
}

protected override string GetLocalAddress(ReadOnlySettings settings)
{
return settings.EndpointName();
}

protected override void Configure(FeatureConfigurationContext context, string connectionString)
{
//Until we refactor the whole address system
Address.IgnoreMachineName();

var useCallbackReceiver = context.Settings.Get<bool>(UseCallbackReceiverSettingKey);
var maxConcurrencyForCallbackReceiver = context.Settings.Get<int>(MaxConcurrencyForCallbackReceiverSettingKey);

var queueName = GetLocalAddress(context.Settings);
var callbackQueue = string.Format("{0}.{1}", queueName, RuntimeEnvironment.MachineName);

//Load all connectionstrings
var collection =
ConfigurationManager
.ConnectionStrings
.Cast<ConnectionStringSettings>()
.Where(x => x.Name.StartsWith("NServiceBus/Transport/"))
.ToDictionary(x => x.Name.Replace("NServiceBus/Transport/", String.Empty), y => y.ConnectionString);

if (String.IsNullOrEmpty(connectionString))
{
throw new ArgumentException("Sql Transport connection string cannot be empty or null.");
}

var container = context.Container;

container.ConfigureComponent<SqlServerQueueCreator>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.ConnectionString, connectionString);

container.ConfigureComponent<SqlServerMessageSender>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.DefaultConnectionString, connectionString)
.ConfigureProperty(p => p.ConnectionStringCollection, collection)
.ConfigureProperty(p => p.CallbackQueue, callbackQueue);

container.ConfigureComponent<SqlServerPollingDequeueStrategy>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.ConnectionString, connectionString);

context.Container.ConfigureComponent(b => new SqlServerStorageContext(b.Build<PipelineExecutor>(), connectionString), DependencyLifecycle.InstancePerUnitOfWork);

if (useCallbackReceiver)
{
var callbackAddress = Address.Parse(callbackQueue);

context.Container.ConfigureComponent<CallbackQueueCreator>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.Enabled, true)
.ConfigureProperty(p => p.CallbackQueueAddress, callbackAddress);

context.Pipeline.Register<PromoteCallbackQueueBehavior.Registration>();
}
context.Container.RegisterSingleton(new SecondaryReceiveConfiguration(workQueue =>
{
//if this isn't the main queue we shouldn't use callback receiver
if (!useCallbackReceiver || workQueue != queueName)
{
return SecondaryReceiveSettings.Disabled();
}
return SecondaryReceiveSettings.Enabled(callbackQueue, maxConcurrencyForCallbackReceiver);
}));
}
}
}

0 comments on commit 781c1eb

Please sign in to comment.