HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Events and event providers

Describes the event management system and event providers in Optimizely.

The events system provides a mechanism for distributing events between Internet Information Services (IIS) applications and Optimizely websites in a load-balanced environment. The event system in Optimizely is provider-based, and you can use the built-in event provider or develop your own customized one.

Event providers

An event provider, optimized for Microsoft Azure, is available on the NuGet feed. The event provider for Azure uses Service Bus for distributing events and requires no server or network detail configuration.

An alternative is to develop a custom event provider adapted to your hosting environment.

Configure an event provider

Add the provider configuration to the startup.cs to use another custom event provider. For example:

public void ConfigureServices(IServiceCollection services)
{
    services.AddCmsEvents();
    services.AddSingleton<EventProvider, MyEventProvider>();
}

See Use the Event API.

Event system process flow

The following procedure describes the logical setup and execution of event system actions.

  1. When an Optimizely Content Management System (CMS) website starts, it does the following:
    a. Creates a secret if one does not already exist in the site database.
    b. Initializes the event host responsible for sending and receiving event messages remotely.
    c. Initializes each event provider that you configured.
    d. Enables the event system when the initialization process is completed (for example, when CMS or Optimizely Customized Commerce has completed initialization).
  2. Code in a site uses the IEventPublisher service to publish an event object.
  3. Any service registered in the service container as an IEventSubscriber<T> where T matches the published event object will be called on its HandleAsync method.
  4. The IEventPublisher will ask the registered EventProvider to send the message.
  5. The EventProvider on the other instance receives the message and raises an event.
  6. The event host calls the IEventPublisher which will call all matching IEventSubscriber<T> services with a context argument indicating that the event was broadcast.

Test the event system

Examples of CMS functionality that use the events system are Cache updates. To test cache events, edit a page on one CMS site and ensure the change is reflected on the second load-balanced CMS website:

  1. On CMS #1, go to a page in the example website.
  2. On CMS #2, enter edit view and go to the same page as in step 1.
  3. On CMS #2, add, edit, or delete some text on the page and click Publish.
  4. On CMS #1, refresh the page and ensure it reflects the information saved in step 3.