Skip to content

Commit

Permalink
Added IsolationLevel to host configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Jun 17, 2013
1 parent 11738d6 commit b4c4b69
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 140 deletions.
19 changes: 19 additions & 0 deletions Rhino.ServiceBus.Tests/HostConfigurationTests.cs
@@ -0,0 +1,19 @@
using System.Transactions;
using Rhino.ServiceBus.Hosting;
using Xunit;

namespace Rhino.ServiceBus.Tests
{
public class HostConfigurationTests
{
[Fact]
public void isolationlevel_is_translated_to_configuration()
{
var hostConfiguration = new HostConfiguration();
hostConfiguration.IsolationLevel(IsolationLevel.ReadCommitted);
var config = hostConfiguration.ToBusConfiguration();

Assert.Equal("ReadCommitted", config.Bus.QueueIsolationLevel);
}
}
}
3 changes: 2 additions & 1 deletion Rhino.ServiceBus.Tests/Rhino.ServiceBus.Tests.csproj
Expand Up @@ -202,6 +202,7 @@
<Compile Include="Containers\StructureMap\ContainerTests.cs" />
<Compile Include="Containers\Unity\Can_host_in_another_app_domain.cs" />
<Compile Include="Containers\Unity\ContainerTests.cs" />
<Compile Include="HostConfigurationTests.cs" />
<Compile Include="RhinoQueues\UsingOneWayBusWithBusNameSpecified.cs" />
<Compile Include="RhinoQueues\CustomizingMessageConstruction.cs" />
<Compile Include="CanRouteMessageToConsumerThroughContainer.cs" />
Expand Down Expand Up @@ -349,4 +350,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
1 change: 1 addition & 0 deletions Rhino.ServiceBus/Config/BusElement.cs
Expand Up @@ -31,6 +31,7 @@ public string Endpoint
public string QueueIsolationLevel
{
get { return this["queueIsolationLevel"] as string; }
set { this["queueIsolationLevel"] = value; }
}

public bool? ConsumeInTransaction
Expand Down
281 changes: 142 additions & 139 deletions Rhino.ServiceBus/Hosting/HostConfiguration.cs
@@ -1,151 +1,154 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Transactions;
using Rhino.ServiceBus.Config;
using System.Reflection;

namespace Rhino.ServiceBus.Hosting
{
public class HostConfiguration
{
private string Name { get; set; }
private string Endpoint { get; set; }
private bool Transactional { get; set; }
private int ThreadCount { get; set; }
private int NumberOfRetries { get; set; }
private string LoadBalancerEndpoint { get; set; }
private string SecurityKey { get; set; }
protected string LogEndpoint { get; set; }
private string Path { get; set; }
private bool EnablePerformanceCounter { get; set; }
using System.Reflection;

namespace Rhino.ServiceBus.Hosting
{
public class HostConfiguration
{
private string Name { get; set; }
private string Endpoint { get; set; }
private bool Transactional { get; set; }
private int ThreadCount { get; set; }
private int NumberOfRetries { get; set; }
private string LoadBalancerEndpoint { get; set; }
private string SecurityKey { get; set; }
protected string LogEndpoint { get; set; }
private string Path { get; set; }
private bool EnablePerformanceCounter { get; set; }
private IsolationLevel QueueIsolationLevel { get; set; }
private IDictionary<string, HostConfigMessageEndpoint> Messages { get; set; }
private IList<Assembly> ScanAssemblies { get; set; }

public HostConfiguration()
{
ThreadCount = 1;
NumberOfRetries = 5;
private IList<Assembly> ScanAssemblies { get; set; }

public HostConfiguration()
{
ThreadCount = 1;
NumberOfRetries = 5;
Messages = new Dictionary<string, HostConfigMessageEndpoint>();
ScanAssemblies = new List<Assembly>();
}

public HostConfiguration Bus(string endpoint)
{
return Bus(endpoint, null);
}

public HostConfiguration Bus(string endpoint, string name)
{
return Bus(endpoint, name, false);
}

public HostConfiguration Bus(string endpoint, string name, bool transactional)
{
Endpoint = endpoint;
Name = name;
Transactional = transactional;
return this;
ScanAssemblies = new List<Assembly>();
}

public HostConfiguration Bus(string endpoint)
{
return Bus(endpoint, null);
}

public HostConfiguration Bus(string endpoint, string name)
{
return Bus(endpoint, name, false);
}

public HostConfiguration Bus(string endpoint, string name, bool transactional)
{
Endpoint = endpoint;
Name = name;
Transactional = transactional;
return this;
}

public HostConfiguration AddAssembly(Assembly assembly)
{
ScanAssemblies.Add(assembly);
return this;
}

public HostConfiguration Threads(int threadCount)
{
ThreadCount = threadCount;
return this;
}

public HostConfiguration Retries(int numberOfRetries)
{
NumberOfRetries = numberOfRetries;
return this;
}

public HostConfiguration LoadBalancer(string endpoint)
{
LoadBalancerEndpoint = endpoint;
return this;
}

public HostConfiguration Logging(string endpoint)
{
LogEndpoint = endpoint;
return this;
}

public HostConfiguration Security(string key)
{
SecurityKey = key;
return this;
}

public HostConfiguration StoragePath(string path)
{
Path = path;
return this;
}

public HostConfiguration EnablePerformanceCounters()
{
EnablePerformanceCounter = true;
return this;
}

public HostConfiguration Receive(string messageName, string endpoint)
{
return Receive(messageName, endpoint, false);
}

public HostConfiguration Receive(string messageName, string endpoint, bool transactional)
{
Messages.Add(messageName, new HostConfigMessageEndpoint
{
Endpoint = endpoint,
Transactional = transactional,
});
return this;
}

public virtual BusConfigurationSection ToBusConfiguration()
{
var config = new BusConfigurationSection();
config.Bus.Endpoint = Endpoint;
config.Bus.ThreadCount = ThreadCount;
config.Bus.NumberOfRetries = NumberOfRetries;
config.Bus.Name = Name;
config.Bus.LoadBalancerEndpoint = LoadBalancerEndpoint;
config.Bus.LogEndpoint = LogEndpoint;
config.Bus.Transactional = Transactional.ToString();
config.Bus.Path = Path;
config.Bus.EnablePerformanceCounters = EnablePerformanceCounter;
}

public HostConfiguration Threads(int threadCount)
{
ThreadCount = threadCount;
return this;
}

public HostConfiguration Retries(int numberOfRetries)
{
NumberOfRetries = numberOfRetries;
return this;
}

public HostConfiguration LoadBalancer(string endpoint)
{
LoadBalancerEndpoint = endpoint;
return this;
}

public HostConfiguration Logging(string endpoint)
{
LogEndpoint = endpoint;
return this;
}

public HostConfiguration IsolationLevel(IsolationLevel isolationLevel)
{
QueueIsolationLevel = isolationLevel;
return this;
}

public HostConfiguration Security(string key)
{
SecurityKey = key;
return this;
}

public HostConfiguration StoragePath(string path)
{
Path = path;
return this;
}

public HostConfiguration EnablePerformanceCounters()
{
EnablePerformanceCounter = true;
return this;
}

public HostConfiguration Receive(string messageName, string endpoint)
{
return Receive(messageName, endpoint, false);
}

public HostConfiguration Receive(string messageName, string endpoint, bool transactional)
{
Messages.Add(messageName, new HostConfigMessageEndpoint
{
Endpoint = endpoint,
Transactional = transactional,
});
return this;
}

public virtual BusConfigurationSection ToBusConfiguration()
{
var config = new BusConfigurationSection();
config.Bus.Endpoint = Endpoint;
config.Bus.ThreadCount = ThreadCount;
config.Bus.NumberOfRetries = NumberOfRetries;
config.Bus.Name = Name;
config.Bus.LoadBalancerEndpoint = LoadBalancerEndpoint;
config.Bus.LogEndpoint = LogEndpoint;
config.Bus.QueueIsolationLevel = QueueIsolationLevel.ToString();
config.Bus.Transactional = Transactional.ToString();
config.Bus.Path = Path;
config.Bus.EnablePerformanceCounters = EnablePerformanceCounter;
config.Security.Key = SecurityKey;
foreach (var assembly in ScanAssemblies)
config.Assemblies.Add(new AssemblyElement { Assembly = assembly });
foreach (var message in Messages)
{
config.MessageOwners.Add(new MessageOwnerElement
{
Name = message.Key,
Endpoint = message.Value.Endpoint,
Transactional = message.Value.Transactional.ToString()
});
}
return config;
}


private class HostConfigMessageEndpoint {
public string Endpoint {
get;
set;
}

public bool Transactional {
get;
set;
}
}
}
config.Assemblies.Add(new AssemblyElement { Assembly = assembly });
foreach (var message in Messages)
{
config.MessageOwners.Add(new MessageOwnerElement
{
Name = message.Key,
Endpoint = message.Value.Endpoint,
Transactional = message.Value.Transactional.ToString()
});
}
return config;
}


private class HostConfigMessageEndpoint
{
public string Endpoint { get; set; }
public bool Transactional { get; set; }
}
}
}

0 comments on commit b4c4b69

Please sign in to comment.