Create a custom event provider
Shows a simple pseudo-code for writing an event provider based on file with options.
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" : {
"EventProviderOptions" : {
"Provider" : "CustomEventProvider.CustomEventProvider, CustomAssembly"
}
},
"CustomEventProviderOptions" : {
"CustomSetting" : "custom setting"
}
}
}
Updated 7 months ago