@@ -14,12 +14,14 @@ class FileBasedRoutingFeature : Feature
1414 static ILog log = LogManager . GetLogger < FileBasedRoutingFeature > ( ) ;
1515
1616 public const string RoutingFilePathKey = "NServiceBus.FileBasedRouting.RoutingFileUri" ;
17+ public const string RouteFileUpdateInterval = "NServiceBus.FileBasedRouting.RouteFileUpdateInterval" ;
1718
1819 public FileBasedRoutingFeature ( )
1920 {
20- Defaults ( s=>
21+ Defaults ( s =>
2122 {
2223 s . SetDefault ( RoutingFilePathKey , UriHelper . FilePathToUri ( "endpoints.xml" ) ) ;
24+ s . SetDefault ( RouteFileUpdateInterval , TimeSpan . FromSeconds ( 30 ) ) ;
2325 s . SetDefault < UnicastSubscriberTable > ( new UnicastSubscriberTable ( ) ) ;
2426 } ) ;
2527 }
@@ -31,6 +33,7 @@ protected override void Setup(FeatureConfigurationContext context)
3133 var unicastRoutingTable = context . Settings . Get < UnicastRoutingTable > ( ) ;
3234 var unicastSubscriberTable = context . Settings . Get < UnicastSubscriberTable > ( ) ;
3335
36+ var routeFileUpdateInterval = context . Settings . Get < TimeSpan > ( RouteFileUpdateInterval ) ;
3437 var routingFileUri = context . Settings . Get < Uri > ( RoutingFilePathKey ) ;
3538 var routingFile = new XmlRoutingFileAccess ( routingFileUri ) ;
3639 var routingFileParser = new XmlRoutingFileParser ( ) ;
@@ -41,7 +44,10 @@ protected override void Setup(FeatureConfigurationContext context)
4144 // ensure the routing file is valid and the routing table is populated before running FeatureStartupTasks
4245 UpdateRoutingTable ( routingFileParser , routingFile , unicastRoutingTable , unicastSubscriberTable , nativeSends , nativePublishes ) ;
4346
44- context . RegisterStartupTask ( new UpdateRoutingTask ( ( ) => UpdateRoutingTable ( routingFileParser , routingFile , unicastRoutingTable , unicastSubscriberTable , nativeSends , nativePublishes ) ) ) ;
47+ if ( routeFileUpdateInterval > TimeSpan . Zero )
48+ {
49+ context . RegisterStartupTask ( new UpdateRoutingTask ( ( ) => UpdateRoutingTable ( routingFileParser , routingFile , unicastRoutingTable , unicastSubscriberTable , nativeSends , nativePublishes ) , routeFileUpdateInterval ) ) ;
50+ }
4551
4652 // if the transport provides native pub/sub support, don't plug in the FileBased pub/sub storage.
4753 if ( context . Settings . Get < TransportInfrastructure > ( ) . OutboundRoutingPolicy . Publishes == OutboundRoutingType . Unicast )
@@ -95,16 +101,18 @@ static void UpdateRoutingTable(XmlRoutingFileParser routingFileParser, XmlRoutin
95101 class UpdateRoutingTask : FeatureStartupTask , IDisposable
96102 {
97103 Action updateRoutingCallback ;
98- Timer updateTimer ;
104+ TimeSpan routeFileUpdateInterval ;
105+ Timer updateTimer ;
99106
100- public UpdateRoutingTask ( Action updateRoutingCallback )
107+ public UpdateRoutingTask ( Action updateRoutingCallback , TimeSpan routeFileUpdateInterval )
101108 {
102- this . updateRoutingCallback = updateRoutingCallback ;
109+ this . updateRoutingCallback = updateRoutingCallback ;
110+ this . routeFileUpdateInterval = routeFileUpdateInterval ;
103111 }
104112
105113 protected override Task OnStart ( IMessageSession session )
106114 {
107- updateTimer = new Timer ( state => updateRoutingCallback ( ) , null , TimeSpan . FromSeconds ( 30 ) , TimeSpan . FromSeconds ( 30 ) ) ;
115+ updateTimer = new Timer ( state => updateRoutingCallback ( ) , null , routeFileUpdateInterval , routeFileUpdateInterval ) ;
108116
109117 return Task . CompletedTask ;
110118 }
0 commit comments