-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added IsolationLevel to host configuration
- Loading branch information
unknown
authored and
unknown
committed
Jun 17, 2013
1 parent
11738d6
commit b4c4b69
Showing
4 changed files
with
164 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} | ||
} |