Skip to content

Instantly share code, notes, and snippets.

@Shazwazza
Created June 11, 2015 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shazwazza/6d75bca3f98d7ef98378 to your computer and use it in GitHub Desktop.
Save Shazwazza/6d75bca3f98d7ef98378 to your computer and use it in GitHub Desktop.
Umbraco 7.3 - Enable DatabaseServerMessenger
public class LoadBalancingConfigurationEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//Replace the server messenger:
ServerMessengerResolver.Current.SetServerMessenger(new BatchedDatabaseServerMessenger(
applicationContext,
true,
//You can customize some options by setting the options parameters here:
new DatabaseServerMessengerOptions
{
//These callbacks will be executed if the server has not been synced
// (i.e. it is a new server or the lastsynced.txt file has been removed)
InitializingCallbacks = new Action[]
{
//rebuild the xml cache file if the server is not synced
() => global::umbraco.content.Instance.RefreshContentFromDatabase(),
//rebuild indexes if the server is not synced
// NOTE: This will rebuild ALL indexes including the members, if developers want to target specific
// indexes then they can adjust this logic themselves.
() => Examine.ExamineManager.Instance.RebuildIndex()
}
}));
//Replace the server registrar (this is optional but allows you to track active servers participating
// in your load balanced environment):
ServerRegistrarResolver.Current.SetServerRegistrar(new DatabaseServerRegistrar(
new Lazy<ServerRegistrationService>(() => applicationContext.Services.ServerRegistrationService),
//You can customize some options by setting the options parameters here:
new DatabaseServerRegistrarOptions()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment