Skip to content

Commit

Permalink
Rolled out installation across code base so that creation of queues w…
Browse files Browse the repository at this point in the history
…ill be done at install time only.
  • Loading branch information
udidahan committed Feb 4, 2011
1 parent 17646dc commit 31d2482
Show file tree
Hide file tree
Showing 21 changed files with 243 additions and 99 deletions.
16 changes: 16 additions & 0 deletions src/distributor/MsmqWorkerAvailabilityManager/Installer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Security.Principal;
using NServiceBus.Installation;
using NServiceBus.Utils;

namespace MsmqWorkerAvailabilityManager
{
class Installer : INeedToInstallSomething<NServiceBus.Installation.Environments.Windows>
{
public void Install(WindowsIdentity identity)
{
var m = NServiceBus.Configure.Instance.Builder.Build<MsmqWorkerAvailabilityManager>();

MsmqUtilities.CreateQueueIfNecessary(m.StorageQueue, identity.Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,8 @@ public class MsmqWorkerAvailabilityManager : IWorkerAvailabilityManager
/// <remarks>The queue provided must be transactional.</remarks>
public string StorageQueue
{
get { return s; }
set
{
s = value;

MsmqUtilities.CreateQueueIfNecessary(value);

var path = MsmqUtilities.GetFullPath(value);

var q = new MessageQueue(path);

if (!q.Transactional)
throw new Exception("Queue must be transactional.");

storageQueue = q;
}
get; set;
}
private string s;

/// <summary>
/// Removes all entries from the worker availability queue
Expand Down Expand Up @@ -90,11 +74,9 @@ public void Start()
{
var path = MsmqUtilities.GetFullPath(StorageQueue);

MsmqUtilities.CreateQueueIfNecessary(StorageQueue);

var q = new MessageQueue(path);
storageQueue = new MessageQueue(path);

if (!q.Transactional)
if (!storageQueue.Transactional)
throw new Exception("Queue must be transactional.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
Expand Down Expand Up @@ -73,6 +72,7 @@
<Compile Include="..\..\CommonAssemblyInfo.cs">
<Link>CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Installer.cs" />
<Compile Include="MsmqWorkerAvailabilityManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public static class ConfigureFaultsForwarder
/// <returns></returns>
public static Configure MessageForwardingInCaseOfFault(this Configure config)
{
string errorQueue;

var section = Configure.GetConfigSection<MessageForwardingInCaseOfFaultConfig>();
if (section == null)
{
Expand All @@ -33,23 +31,25 @@ public static Configure MessageForwardingInCaseOfFault(this Configure config)
throw new ConfigurationErrorsException("Could not find backup configuration section 'MsmqTransportConfig' in order to locate the error queue.");


errorQueue = msmq.ErrorQueue;
ErrorQueue = msmq.ErrorQueue;
}
else
errorQueue = section.ErrorQueue;
ErrorQueue = section.ErrorQueue;

if(string.IsNullOrEmpty(errorQueue))
if(string.IsNullOrEmpty(ErrorQueue))
throw new ConfigurationErrorsException("Faults forwarding requires a error queue to be specified. Please add a 'MessageForwardingInCaseOfFaultConfig' section to your app.config");

//TODO: this should probably be moved to a new IManageFaults.Start|Init method instead. Check with Udi
MsmqUtilities.CreateQueueIfNecessary(errorQueue);

config.Configurer.ConfigureComponent<FaultManager>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(fm => fm.ErrorQueue, errorQueue);
.ConfigureProperty(fm => fm.ErrorQueue, ErrorQueue);

return config;
}

/// <summary>
/// The queue to which to forward errors.
/// </summary>
public static string ErrorQueue { get; set; }

private static ILog Logger = LogManager.GetLogger("MessageForwardingInCaseOfFault");
}

Expand Down
18 changes: 18 additions & 0 deletions src/impl/faults/NServiceBus.Faults.Forwarder.Config/Installer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using NServiceBus.Installation;
using NServiceBus.Utils;

namespace NServiceBus.Faults.Forwarder.Config
{
class Installer : INeedToInstallSomething<Installation.Environments.Windows>
{
public void Install(WindowsIdentity identity)
{
MsmqUtilities.CreateQueueIfNecessary(ConfigureFaultsForwarder.ErrorQueue, identity.Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
<HintPath>..\..\..\..\build\nservicebus.core\NServiceBus.Faults.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NServiceBus.Installation">
<HintPath>..\..\..\..\build\nservicebus.core\NServiceBus.Installation.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NServiceBus.Installation.Windows">
<HintPath>..\..\..\..\build\nservicebus.core\NServiceBus.Installation.Windows.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NServiceBus.ObjectBuilder, Version=2.1.0.0, Culture=neutral, PublicKeyToken=9fc386479f8a226c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\build\nservicebus.core\NServiceBus.ObjectBuilder.dll</HintPath>
Expand Down Expand Up @@ -97,6 +105,7 @@
<Link>CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ConfigureFaultsForwarder.cs" />
<Compile Include="Installer.cs" />
<Compile Include="MessageForwardingInCaseOfFaultConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ public class MsmqSubscriptionStorage : ISubscriptionStorage
{
void ISubscriptionStorage.Init()
{
string path = MsmqUtilities.GetFullPath(Queue);

q = new MessageQueue(path);

bool transactional;
try
{
transactional = q.Transactional;
}
catch (Exception ex)
{
throw new ArgumentException(string.Format("There is a problem with the subscription storage queue {0}. See enclosed exception for details.", Queue), ex);
}

if (!transactional)
throw new ArgumentException("Queue must be transactional (" + Queue + ").");

var mpf = new MessagePropertyFilter();
mpf.SetAll();

q.Formatter = new XmlMessageFormatter(new[] { typeof(string) });

q.MessageReadPropertyFilter = mpf;

foreach (var m in q.GetAllMessages())
{
var subscriber = m.Label;
Expand Down Expand Up @@ -168,38 +192,8 @@ private MessageQueueTransactionType GetTransactionType()
/// </summary>
public string Queue
{
get { return queue; }
set
{
queue = value;
MsmqUtilities.CreateQueueIfNecessary(value);

string path = MsmqUtilities.GetFullPath(value);

q = new MessageQueue(path);

bool transactional;
try
{
transactional = q.Transactional;
}
catch(Exception ex)
{
throw new ArgumentException(string.Format("There is a problem with the subscription storage queue {0}. See enclosed exception for details.", value), ex);
}

if (!transactional)
throw new ArgumentException("Queue must be transactional (" + value + ").");

var mpf = new MessagePropertyFilter();
mpf.SetAll();

q.Formatter = new XmlMessageFormatter(new[] { typeof(string) });

q.MessageReadPropertyFilter = mpf;
}
get; set;
}
private string queue;

#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NServiceBus.Unicast.Subscriptions.Msmq.Config;
using Common.Logging;
using NServiceBus.Config;
using NServiceBus.ObjectBuilder;
using NServiceBus.Unicast.Subscriptions.Msmq;

namespace NServiceBus
{
Expand All @@ -19,12 +18,26 @@ public static class ConfigureMsmqSubscriptionStorage
/// </summary>
/// <param name="config"></param>
/// <returns></returns>
public static ConfigMsmqSubscriptionStorage MsmqSubscriptionStorage(this Configure config)
public static Configure MsmqSubscriptionStorage(this Configure config)
{
ConfigMsmqSubscriptionStorage cfg = new ConfigMsmqSubscriptionStorage();
cfg.Configure(config);
var cfg = Configure.GetConfigSection<MsmqSubscriptionStorageConfig>();

return cfg;
if (cfg == null)
Logger.Warn("Could not find configuration section for Msmq Subscription Storage.");

Queue = (cfg != null ? cfg.Queue : "NServiceBus_Subscriptions");

var storageConfig = config.Configurer.ConfigureComponent<MsmqSubscriptionStorage>(DependencyLifecycle.SingleInstance);
storageConfig.ConfigureProperty(s => s.Queue, Queue);

return config;
}

/// <summary>
/// Queue used to store subscriptions.
/// </summary>
public static string Queue { get; set; }

private static readonly ILog Logger = LogManager.GetLogger(typeof(MsmqSubscriptionStorage));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Security.Principal;
using NServiceBus.Installation;
using NServiceBus.Utils;

namespace NServiceBus.Unicast.Subscriptions.Msmq.Config
{
/// <summary>
/// Class responssible for installing the MSMQ subscription storage.
/// </summary>
public class Installer : INeedToInstallSomething<Installation.Environments.Windows>
{
/// <summary>
/// Installs the queue.
/// </summary>
/// <param name="identity"></param>
public void Install(WindowsIdentity identity)
{
MsmqUtilities.CreateQueueIfNecessary(ConfigureMsmqSubscriptionStorage.Queue, identity.Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
<HintPath>..\..\..\..\..\build\nservicebus.core\NServiceBus.Config.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NServiceBus.Installation">
<HintPath>..\..\..\..\..\build\nservicebus.core\NServiceBus.Installation.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NServiceBus.Installation.Windows">
<HintPath>..\..\..\..\..\build\nservicebus.core\NServiceBus.Installation.Windows.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NServiceBus.ObjectBuilder">
<HintPath>..\..\..\..\..\build\nservicebus.core\NServiceBus.ObjectBuilder.dll</HintPath>
<Private>False</Private>
Expand All @@ -71,6 +79,10 @@
<HintPath>..\..\..\..\..\build\nservicebus.core\NServiceBus.Unicast.Subscriptions.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NServiceBus.Utils">
<HintPath>..\..\..\..\..\build\nservicebus.core\NServiceBus.Utils.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core">
Expand All @@ -83,7 +95,7 @@
<Compile Include="..\..\..\..\CommonAssemblyInfo.cs">
<Link>CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ConfigMsmqSubscriptionStorage.cs" />
<Compile Include="Installer.cs" />
<Compile Include="ConfigureMsmqSubscriptionStorage.cs" />
<Compile Include="MsmqSubscriptionStorageConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ namespace NServiceBus
{
public static class ConfigureMsmqMessageQueue
{
/// <summary>
/// Indicates that MsmqMessageQueue has been selected.
/// </summary>
public static bool Selected { get; set; }

/// <summary>
/// Use MSMQ for your queuing infrastructure.
/// </summary>
/// <param name="config"></param>
/// <returns></returns>
public static Configure MsmqTransport(this Configure config)
{
Selected = true;

config.Configurer.ConfigureComponent<MsmqMessageReceiver>(DependencyLifecycle.SingleInstance);
config.Configurer.ConfigureComponent<MsmqMessageSender>(DependencyLifecycle.SingleInstance);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using NServiceBus.Installation;
using NServiceBus.Utils;

namespace NServiceBus.Unicast.Queuing.Msmq.Config
{
class Installer : INeedToInstallSomething<Installation.Environments.Windows>
{
public void Install(WindowsIdentity identity)
{
if (!ConfigureMsmqMessageQueue.Selected)
return;

var bus = NServiceBus.Configure.Instance.Builder.Build<UnicastBus>();

MsmqUtilities.CreateQueueIfNecessary(bus.Address, identity.Name);
}
}
}
Loading

0 comments on commit 31d2482

Please sign in to comment.