Skip to content

Commit eb5592b

Browse files
harrisonmeisterPliner
authored andcommitted
Update EasyNetQ.Scheduler with EnableLegacyConventions setting (#923)
* Update EasyNetQ.Scheduler to include config setting to be able to invoke legacy conventions on creation of rabbit bus * Also update EasyNetQ.Scheduler.Mongo to include config setting to be able to invoke legacy conventions on creation of rabbit bus
1 parent 6a3b2cf commit eb5592b

File tree

10 files changed

+56
-6
lines changed

10 files changed

+56
-6
lines changed

Source/EasyNetQ.Scheduler.Mongo.Tests/SchedulerServiceTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public SchedulerServiceTests()
2626
HandleTimeoutInterval = TimeSpan.FromSeconds(1),
2727
PublishInterval = TimeSpan.FromSeconds(1),
2828
SubscriptionId = "Scheduler",
29-
PublishMaxSchedules = 2
29+
PublishMaxSchedules = 2,
30+
EnableLegacyConventions = false
3031
});
3132
}
3233

Source/EasyNetQ.Scheduler.Mongo/ConfigurationBase.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,17 @@ protected static TimeSpan GetTimeSpanAppSettings(string settingKey)
2828
}
2929
return value;
3030
}
31+
32+
protected static bool GetBoolAppSetting(string settingKey)
33+
{
34+
var appSetting = ConfigurationManager.AppSettings[settingKey];
35+
bool value;
36+
if (!bool.TryParse(appSetting, out value))
37+
{
38+
throw new ApplicationException(String.Format("AppSetting '{0}' value '{1}' is not a valid boolean",
39+
settingKey, appSetting));
40+
}
41+
return value;
42+
}
3143
}
3244
}

Source/EasyNetQ.Scheduler.Mongo/SchedulerServiceConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class SchedulerServiceConfiguration : ConfigurationBase, ISchedulerServic
1010
public TimeSpan PublishInterval { get; set; }
1111
public TimeSpan HandleTimeoutInterval { get; set; }
1212
public int PublishMaxSchedules { get; set; }
13+
public bool EnableLegacyConventions { get; set; }
1314

1415
public static SchedulerServiceConfiguration FromConfigFile()
1516
{
@@ -19,6 +20,7 @@ public static SchedulerServiceConfiguration FromConfigFile()
1920
PublishInterval = GetTimeSpanAppSettings("publishInterval"),
2021
PublishMaxSchedules = GetIntAppSetting("publishMaxSchedules"),
2122
HandleTimeoutInterval = GetTimeSpanAppSettings("handleTimeoutInterval"),
23+
EnableLegacyConventions = GetBoolAppSetting("enableLegacyConventions")
2224
};
2325
}
2426
}

Source/EasyNetQ.Scheduler.Mongo/SchedulerServiceFactory.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ public static class SchedulerServiceFactory
88
{
99
public static ISchedulerService CreateScheduler()
1010
{
11-
var bus = RabbitHutch.CreateBus("host=localhost");
11+
var serviceConfig = SchedulerServiceConfiguration.FromConfigFile();
12+
var bus = RabbitHutch.CreateBus("host=localhost", sr =>
13+
{
14+
if (serviceConfig.EnableLegacyConventions)
15+
{
16+
sr.EnableLegacyConventions();
17+
}
18+
});
1219

1320
return new SchedulerService(
1421
bus,

Source/EasyNetQ.Scheduler.Mongo/app.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
<!-- How long between each handle for messages failed to publish-->
3737
<add key="handleTimeoutInterval" value="00:05:00"/>
38+
39+
<!-- Enable Legacy Conventions for Rabbit Queues -->
40+
<add key="enableLegacyConventions" value="false"/>
3841
</appSettings>
3942

4043
<log4net>

Source/EasyNetQ.Scheduler.Tests/SchedulerServiceTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public SchedulerServiceTests()
3232
new SchedulerServiceConfiguration
3333
{
3434
PublishIntervalSeconds = 1,
35-
PurgeIntervalSeconds = 1
35+
PurgeIntervalSeconds = 1,
36+
EnableLegacyConventions = false
3637
});
3738
}
3839

Source/EasyNetQ.Scheduler/ConfigurationBase.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,17 @@ public static int GetIntAppSetting(string settingKey)
2828
}
2929
return value;
3030
}
31+
32+
public static bool GetBoolAppSetting(string settingKey)
33+
{
34+
var appSetting = ConfigurationManager.AppSettings[settingKey];
35+
bool value;
36+
if (!bool.TryParse(appSetting, out value))
37+
{
38+
throw new ApplicationException(string.Format("AppSetting '{0}' value '{1}' is not a valid boolean",
39+
settingKey, appSetting));
40+
}
41+
return value;
42+
}
3143
}
3244
}

Source/EasyNetQ.Scheduler/SchedulerServiceConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ public class SchedulerServiceConfiguration : ConfigurationBase
44
{
55
public int PublishIntervalSeconds { get; set; }
66
public int PurgeIntervalSeconds { get; set; }
7+
public bool EnableLegacyConventions { get; set; }
78

89
public static SchedulerServiceConfiguration FromConfigFile()
910
{
1011
return new SchedulerServiceConfiguration
1112
{
1213
PublishIntervalSeconds = GetIntAppSetting("PublishIntervalSeconds"),
13-
PurgeIntervalSeconds = GetIntAppSetting("PurgeIntervalSeconds")
14+
PurgeIntervalSeconds = GetIntAppSetting("PurgeIntervalSeconds"),
15+
EnableLegacyConventions = GetBoolAppSetting("EnableLegacyConventions")
1416
};
1517
}
1618
}

Source/EasyNetQ.Scheduler/SchedulerServiceFactory.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ public static class SchedulerServiceFactory
66
{
77
public static ISchedulerService CreateScheduler()
88
{
9-
var bus = RabbitHutch.CreateBus();
9+
var serviceConfig = SchedulerServiceConfiguration.FromConfigFile();
10+
var bus = RabbitHutch.CreateBus(sr =>
11+
{
12+
if (serviceConfig.EnableLegacyConventions)
13+
{
14+
sr.EnableLegacyConventions();
15+
}
16+
});
1017
return new SchedulerService(
11-
bus,
18+
bus,
1219
new ScheduleRepository(ScheduleRepositoryConfiguration.FromConfigFile(), () => DateTime.UtcNow),
1320
SchedulerServiceConfiguration.FromConfigFile());
1421
}

Source/EasyNetQ.Scheduler/app.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
<!-- How long between each purge -->
3030
<add key="PurgeIntervalSeconds" value="5"/>
31+
32+
<!-- Enable Legacy Conventions for Rabbit Queues -->
33+
<add key="EnableLegacyConventions" value="false"/>
3134
</appSettings>
3235

3336
<log4net>

0 commit comments

Comments
 (0)