99namespace NServiceBus . FileBasedRouting
1010{
1111 using System . IO ;
12+ using Logging ;
1213
13- public class FileBasedRoutingFeature : Feature
14+ class FileBasedRoutingFeature : Feature
1415 {
15- const string RoutingFilePathKey = "NServiceBus.FileBasedRouting.RoutingFilePath" ;
16+ static ILog log = LogManager . GetLogger < FileBasedRoutingFeature > ( ) ;
17+
18+ public const string RoutingFilePathKey = "NServiceBus.FileBasedRouting.RoutingFilePath" ;
1619
1720 public FileBasedRoutingFeature ( )
1821 {
19- Defaults ( s =>
22+ Defaults ( s=>
2023 {
2124 s . SetDefault ( RoutingFilePathKey , "endpoints.xml" ) ;
2225 s . SetDefault < UnicastSubscriberTable > ( new UnicastSubscriberTable ( ) ) ;
@@ -25,22 +28,26 @@ public FileBasedRoutingFeature()
2528
2629 protected override void Setup ( FeatureConfigurationContext context )
2730 {
31+ var transportInfrastructure = context . Settings . Get < TransportInfrastructure > ( ) ;
32+
2833 var unicastRoutingTable = context . Settings . Get < UnicastRoutingTable > ( ) ;
2934 var unicastSubscriberTable = context . Settings . Get < UnicastSubscriberTable > ( ) ;
3035
3136 var routingFilePath = GetRoutingFilePath ( context ) ;
3237 var routingFile = new XmlRoutingFileAccess ( routingFilePath ) ;
3338 var routingFileParser = new XmlRoutingFileParser ( ) ;
3439
40+ var nativeSends = transportInfrastructure . OutboundRoutingPolicy . Sends == OutboundRoutingType . Multicast ;
41+ var nativePublishes = transportInfrastructure . OutboundRoutingPolicy . Publishes == OutboundRoutingType . Multicast ;
42+
3543 // ensure the routing file is valid and the routing table is populated before running FeatureStartupTasks
36- UpdateRoutingTable ( routingFileParser , routingFile , unicastRoutingTable , unicastSubscriberTable ) ;
44+ UpdateRoutingTable ( routingFileParser , routingFile , unicastRoutingTable , unicastSubscriberTable , nativeSends , nativePublishes ) ;
3745
38- context . RegisterStartupTask ( new UpdateRoutingTask ( routingFileParser , routingFile , unicastRoutingTable , unicastSubscriberTable ) ) ;
46+ context . RegisterStartupTask ( new UpdateRoutingTask ( ( ) => UpdateRoutingTable ( routingFileParser , routingFile , unicastRoutingTable , unicastSubscriberTable , nativeSends , nativePublishes ) ) ) ;
3947
4048 // if the transport provides native pub/sub support, don't plug in the FileBased pub/sub storage.
4149 if ( context . Settings . Get < TransportInfrastructure > ( ) . OutboundRoutingPolicy . Publishes == OutboundRoutingType . Unicast )
4250 {
43- var transportInfrastructure = context . Settings . Get < TransportInfrastructure > ( ) ;
4451 var routingConnector = new PublishRoutingConnector (
4552 unicastSubscriberTable ,
4653 context . Settings . Get < EndpointInstances > ( ) ,
@@ -60,7 +67,7 @@ static string GetRoutingFilePath(FeatureConfigurationContext context)
6067 return Path . IsPathRooted ( configuredRoutingFilePath ) ? configuredRoutingFilePath : Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , configuredRoutingFilePath ) ;
6168 }
6269
63- static void UpdateRoutingTable ( XmlRoutingFileParser routingFileParser , XmlRoutingFileAccess routingFile , UnicastRoutingTable routingTable , UnicastSubscriberTable subscriberTable )
70+ static void UpdateRoutingTable ( XmlRoutingFileParser routingFileParser , XmlRoutingFileAccess routingFile , UnicastRoutingTable routingTable , UnicastSubscriberTable subscriberTable , bool nativeSends , bool nativePublishes )
6471 {
6572 var endpoints = routingFileParser . Parse ( routingFile . Read ( ) ) ;
6673
@@ -72,11 +79,19 @@ static void UpdateRoutingTable(XmlRoutingFileParser routingFileParser, XmlRoutin
7279 var route = UnicastRoute . CreateFromEndpointName ( endpoint . LogicalEndpointName ) ;
7380 foreach ( var commandType in endpoint . Commands )
7481 {
82+ if ( nativeSends )
83+ {
84+ log . Warn ( $ "Selected transport uses native command routing. Route for { commandType . FullName } to { endpoint . LogicalEndpointName } configured in { routingFile . FilePath } will be ignored.") ;
85+ }
7586 commandRoutes . Add ( new RouteTableEntry ( commandType , route ) ) ;
7687 }
7788
7889 foreach ( var eventType in endpoint . Events )
7990 {
91+ if ( nativePublishes )
92+ {
93+ log . Warn ( $ "Selected transport uses native event routing. Route for { eventType . FullName } to { endpoint . LogicalEndpointName } configured in { routingFile . FilePath } will be ignored.") ;
94+ }
8095 eventRoutes . Add ( new RouteTableEntry ( eventType , route ) ) ;
8196 }
8297 }
@@ -87,23 +102,17 @@ static void UpdateRoutingTable(XmlRoutingFileParser routingFileParser, XmlRoutin
87102
88103 class UpdateRoutingTask : FeatureStartupTask , IDisposable
89104 {
90- XmlRoutingFileParser routingFileParser ;
91- XmlRoutingFileAccess routingFile ;
92- UnicastRoutingTable unicastRoutingTable ;
93- UnicastSubscriberTable subscriberTable ;
105+ Action updateRoutingCallback ;
94106 Timer updateTimer ;
95107
96- public UpdateRoutingTask ( XmlRoutingFileParser routingFileParser , XmlRoutingFileAccess routingFile , UnicastRoutingTable unicastRoutingTable , UnicastSubscriberTable subscriberTable )
108+ public UpdateRoutingTask ( Action updateRoutingCallback )
97109 {
98- this . routingFileParser = routingFileParser ;
99- this . routingFile = routingFile ;
100- this . unicastRoutingTable = unicastRoutingTable ;
101- this . subscriberTable = subscriberTable ;
110+ this . updateRoutingCallback = updateRoutingCallback ;
102111 }
103112
104113 protected override Task OnStart ( IMessageSession session )
105114 {
106- updateTimer = new Timer ( state => UpdateRoutingTable ( routingFileParser , routingFile , unicastRoutingTable , subscriberTable ) , null , TimeSpan . FromSeconds ( 30 ) , TimeSpan . FromSeconds ( 30 ) ) ;
115+ updateTimer = new Timer ( state => updateRoutingCallback ( ) , null , TimeSpan . FromSeconds ( 30 ) , TimeSpan . FromSeconds ( 30 ) ) ;
107116
108117 return Task . CompletedTask ;
109118 }
0 commit comments