Created
July 6, 2011 05:17
-
-
Save abdullin/1066616 to your computer and use it in GitHub Desktop.
Sample of running AppEngine inside the Web Role (for Lokad.CQRS v2.0)
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
// Sample of running AppEngine inside the Web Role, essentially merging | |
// 1 worker role and 1 web role (for Lokad.CQRS v2.0) | |
// For explanation see: http://abdullin.com/journal/2011/7/6/lokadcqrs-can-make-windows-azure-cheaper-for-you.html | |
public class WebRole : RoleEntryPoint | |
{ | |
CqrsEngineHost _host; | |
readonly CancellationTokenSource _source = new CancellationTokenSource(); | |
public override bool OnStart() | |
{ | |
ServicePointManager.DefaultConnectionLimit = 48; | |
RoleEnvironment.Changing += RoleEnvironmentChanging; | |
_host = BuildBusForWorker.Configure().Build(); | |
return base.OnStart(); | |
} | |
public override void Run() | |
{ | |
var task = _host.Start(_source.Token); | |
task.Wait() | |
} | |
public override void OnStop() | |
{ | |
_source.Cancel(); | |
base.OnStop(); | |
} | |
private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e) | |
{ | |
// If a configuration setting is changing | |
if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange)) | |
{ | |
// Set e.Cancel to true to restart this role instance | |
e.Cancel = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment