forked from hibernating-rhinos/rhino-esb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRhinoServiceBusFacility.cs
108 lines (96 loc) · 3.83 KB
/
RhinoServiceBusFacility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Configuration;
using Castle.Core;
using Castle.Core.Configuration;
using Castle.MicroKernel;
using Castle.MicroKernel.Registration;
using Rhino.ServiceBus.Actions;
using System.Transactions;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.Msmq;
namespace Rhino.ServiceBus.Impl
{
public class RhinoServiceBusFacility : AbstractRhinoServiceBusFacility
{
protected readonly List<MessageOwner> messageOwners = new List<MessageOwner>();
protected override void ReadConfiguration()
{
ReadBusConfiguration();
new MessageOwnersConfigReader(FacilityConfig, messageOwners).ReadMessageOwners();
}
protected override void RegisterComponents()
{
Kernel.Register(
Component.For<IConsumerLocator>()
.ImplementedBy<CastleConsumerLocator>(),
Component.For<IDeploymentAction>()
.ImplementedBy<CreateLogQueueAction>(),
Component.For<IDeploymentAction>()
.ImplementedBy<CreateQueuesAction>(),
Component.For<IServiceBus, IStartableServiceBus>()
.ImplementedBy<DefaultServiceBus>()
.LifeStyle.Is(LifestyleType.Singleton)
.DependsOn(new
{
messageOwners = messageOwners.ToArray(),
})
.Parameters(Parameter.ForKey("modules").Eq(CreateModuleConfigurationNode())
)
);
}
private IConfiguration CreateModuleConfigurationNode()
{
var config = new MutableConfiguration("array");
foreach (Type type in messageModules)
{
config.CreateChild("item", "${" + type.FullName + "}");
}
return config;
}
protected void ReadBusConfiguration()
{
IConfiguration busConfig = FacilityConfig.Children["bus"];
if (busConfig == null)
throw new ConfigurationErrorsException("Could not find 'bus' node in configuration");
string retries = busConfig.Attributes["numberOfRetries"];
int result;
if (int.TryParse(retries, out result))
NumberOfRetries = result;
string threads = busConfig.Attributes["threadCount"];
if (int.TryParse(threads, out result))
ThreadCount = result;
string isolationLevel = busConfig.Attributes["queueIsolationLevel"];
if (!string.IsNullOrEmpty(isolationLevel))
queueIsolationLevel = (IsolationLevel)Enum.Parse(typeof(IsolationLevel), isolationLevel);
string inTransaction = busConfig.Attributes["consumeInTransaction"];
bool boolResult;
if (bool.TryParse(inTransaction, out boolResult))
consumeInTxn = boolResult;
string uriString = busConfig.Attributes["endpoint"];
Uri endpoint;
if (Uri.TryCreate(uriString, UriKind.Absolute, out endpoint) == false)
{
throw new ConfigurationErrorsException(
"Attribute 'endpoint' on 'bus' has an invalid value '" + uriString + "'");
}
Endpoint = endpoint;
string transactionalString = busConfig.Attributes["transactional"];
bool temp;
if (bool.TryParse(transactionalString, out temp))
{
Transactional = temp ? TransactionalOptions.Transactional : TransactionalOptions.NonTransactional;
}
else if(transactionalString != null)
{
throw new ConfigurationErrorsException(
"Attribute 'transactional' on 'bus' has an invalid value '" + uriString + "'");
}
}
public IFacility UseFlatQueueStructure()
{
UseFlatQueue = true;
return this;
}
}
}