Create a custom event provider
Learn to create and configure a custom event provider for Optimizely CMS 13. Implement EventProvider and define options in appsettings.json to manage event distribution.
You can find more providers, such as Amazon and Azure, in the Optimizely NuGet feed.
using EPiServer.Events;
using EPiServer.Events.Providers;
using EPiServer.ServiceLocation;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace CustomEventProvider {
[Options]
public class CustomEventProviderOptions {
public string CustomSetting {
get;
set;
} = "custom setting";
}
public class CustomEventProvider: EventProvider {
public CustomEventProvider(CustomEventProviderOptions options) {}
public override Task InitializeAsync() {
//Put initialization code here, example waiting for external callback and call OnMessageReceived(messages)
}
public override Task SendMessageAsync(EventMessage message, CancellationToken cancellationToken) {
//Put code to sends the provided message to other related sites.
}
public override void SendMessage(EventMessage message) {
throw new NotSupportedException("It doesn't need because there is already async version.");
}
}
}Configure an event provider
To add a custom event provider, add the provider configuration to appsettings.json as the following example shows:
{
"EPiServer" : {
"Cms" : {
"EventProvider" : {
"Provider" : "CustomEventProvider.CustomEventProvider, CustomAssembly"
}
},
"CustomEventProvider" : {
"CustomSetting" : "custom setting"
}
}
}Updated 28 days ago
