Skip to content

Getting Started

Jezz Santos edited this page Nov 26, 2017 · 11 revisions

Install from NuGet:

Install-Package ServiceStack.Webhooks

Simply add the WebhookFeature in your AppHost.Configure() method:

public override void Configure(Container container)
{
    // Register the ValidationFeature and AuthFeature first
    Plugins.Add(new ValidationFeature());
    Plugins.Add(new AuthFeature(...));

    Plugins.Add(new WebhookFeature
    {
        .. any customization for your environment
    });
}

Note: You must add the WebhookFeature after you add any of these plugins:

  • new ValidationFeature() - this is necessary to validate incoming messages to the SubscriptionService
  • new AuthFeature() - not necessary unless you want to secure access to the SubscriptionService. But if you do, don't forget to checkout how to customize the security of the Subscription Service

Customizing the WebhookFeature

By default, the following components are installed by the WebhookFeature (primarily so you can quickly get started with using the feature):

  • SubscriptionStore: MemorySubscriptionStore to store all registered subscriptions
  • Event Sink: AppHostEventSink to relay raised events directly from your service to subscribers.

WARNING: In production systems these default components will need to be replaced, by customizing your configuration of the WebhookFeature:

public override void Configure(Container container)
{
    // Register the ValidationFeature and AuthFeature first
    Plugins.Add(new ValidationFeature());
    Plugins.Add(new AuthFeature(...));

    // Register your own ISubscriptionStore and IEventSink
    container.Register<ISubscriptionStore>(new MyDbSubscriptionStore());
    container.Register<IEventSink>(new MyAsyncEventSink());

    Plugins.Add(new WebhookFeature
    {
        .. any customization for your environment
    });
}
  • Configure a ISubscriptionStore with one that is more appropriate to more persistent storage, like an OrmLiteStore or RedisStore, or a stores subscriptions using a database of your choice. WARNING: If you don't do this, and you continue to use the built-in MemorySubscriptionStore your subscriptions will be lost when your AppHost is restarted.
  • (Optional) Consider configuring a IEventSink with one that introduces some buffering and asynchronicity between raising events and relaying (POSTing) them to registered subscribers, like an Trigger, Queue, Bus-based implementation of your choice. WARNING: If you don't do this, and you continue to use the built-in AppHostEventSink your subscribers will be notified in the same thread that you raised the event, which will significantly slow down your services.

The following properties are also configurable on the WebhookFeature:

  • IncludeSubscriptionService - (bool) whether to register the ISubscriptionService, and all of its dependencies in this service. true by default .
  • SecureRelayRoles - (array of string) these are a list of delimited roles that have access to call the following routes: GET /subscriptions/search and PUT /subscriptions/history. "service" by default.
  • SecureSubscriberRoles - (array of string) these are a list of delimited roles that have access to call the following routes: GET /subscriptions, GET /subscriptions/{Id}, PUT /subscriptions/{Id}, POST /subscriptions and DELETE /subscriptions/{Id}. "user" by default.
  • PublishEventFilter - (delegate of WebhookEvent) - optional handler when any webhook event is raised by calling IWebhooks.Publish(). This delegate allows you to pre-process all events and add/change the event before it relayed to subscribers, for example in multi-tenanted scenarios. null by default.

Subscription Service

You can also customize several things about the 'Subscription Service'.

See Subscription Service for more details on that.