Just a short piece on how to act on Optimizely‘s remote events. While in later versions you may use for instance RabbitMQ or ActiveMQ, still being on 11 will have you using the older event distribution. For attaching your own handlers to the received event, you will need to get an instance of the IEventProviderAccessor rather than accessing events directly like with publish events via IContentEvents. Optimizely have plenty of their own events, so you’ll need to filter on what you’re interested in.
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class MyRemoteEventsInitializer : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
IEventProviderAccessor accessor = ServiceLocator.Current.GetInstance<IEventProviderAccessor>();
accessor.Provider.MessageReceived += MessageReceived_MyHandler;
}
public void Uninitialize(InitializationEngine context)
{
IEventProviderAccessor accessor = ServiceLocator.Current.GetInstance<IEventProviderAccessor>();
accessor.Provider.MessageReceived -= MessageReceived_MyHandler;
}
private void MessageReceived_MyHandler(object sender, EventMessageEventArgs e)
{
if (e.Message.ServerName == Environment.MachineName)
{
return;
}
if (!IsMyOwnEvent(e.Message.Parameter))
{
return;
}
// Do work
}