Skip to content

3.2 HTTP Server Configuration

Jesse Sweetland edited this page Jun 14, 2017 · 5 revisions

Platibus includes a standalone HTTP server based on the .NET System.Net.HttpListener class. This server can be started via the static Start method of the Platibus.Http.HttpServer class.

The HttpServer.Start method has two overloads. The first accepts an optional string parameter specifying the name of the Platibus.Http.HttpServerConfigurationSection to load from the app.config (the default section name is "platibus.httpserver"). If this overload is used, the HTTP server will be configured according to the declarative configuration specified in the named configuration section, filtered through any concrete public IConfigurationHook implementations found in any of the assemblies in the the app domain base directory.

Declarative configuration example:

<configuration>
  <configSections>
    <section name="platibus.httpserver" type="Platibus.Http.HttpServerConfigurationSection, Platibus" />
  </configSections>
  <platibus.httpserver baseUri="http://crm.example.com:52180/platibus" replyTimeout="00:00:30">
    <queueing provider="SQLite" path="platibus\queues" />
    <subscriptionTracking provider="Filesystem" path="platibus\subscriptions" />
    <endpoints>
      <add name="provisioning" address="http://provisioning.example.com:52180/platibus/" />
    </endpoints>
    <topics>
      <add name="CustomerEvents" />
      <add name="OrderEvents" />
    </topics>
    <sendRules>
      <add namePattern=".*Provision.*" endpoint="provisioning" />
    </sendRules>
    <subscriptions>
      <add endpoint="provisioning" topic="ProvisioningEvents" />
    </subscriptions>
  </platibus.httpserver>
</configuration>

The second overload accepts the Platibus.Http.IHttpServerConfiguration containing all of the necessary configuration data for the HTTP server. This overload bypasses all declarative configuration and uses the supplied configuration object (configuration hooks are not called). This version can be used to programmatically specify 100% of the configuration for the HTTP server.

In addition to the common bus configuration elements, the HTTP server configuration features some options specific to the HTTP server.

Authentication Schemes

The list of supported authentication schemes can be specified in the <authenticationSchemes> element or in the IHttpServerConfiguration.AuthenticationSchemes flag.

Declarative example:

<platibus.httpserver>
  <authenticationSchemes>
    <add scheme="Windows"/>
    <add scheme="Basic"/>
  </authenticationSchemes>
</platibus.httpserver>

Programmatic example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        var httpServerConfiguration = configuration as HttpServerConfiguration;
        if (httpServerConfiguration != null)
        {
            var authenticationSchemes = 
                AuthenticationSchemes.Windows | 
                AuthenticationSchemes.Basic
            httpServerConfiguration.AuthenticationSchemes = authenticationSchemes;
        }
    }
}

Authorization Service

The authorization service is an optional component that can be used to restrict a remote caller's ability to send messages or subscribe to topics. If a Basic authentication scheme is used, then an authorization service may be needed to authenticate the supplied credentials (see Platibus.Http.BasicAuthorizationService).

Programmatic example:

public class CustomAuthorizationService : BasicAuthorizationService
{
    public bool Authenticate(string username, string password)
    {
        // Verify credentials against a database, etc.
        return true;
    }
}

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        var httpServerConfiguration = configuration as HttpServerConfiguration;
        if (httpServerConfiguration != null)
        {
            var authorizationService = new CustomAuthorizationService();
            httpServerConfiguration.AuthorizationService = authorizationService;
        }
    }
}

Message Queueing Service

The message queueing service provides the HTTP server with a means of persisting important messages until they are successfully processed (outbound messages are queued until they are successfully sent; inbound messages are queued until they are acknowledged). The message queueing service can be specified declaratively or programmatically.

See 3.4 Message Queueing for more details.

Declarative example:

<platibus.httpserver>
  <queueing provider="Filesystem" path="C:\platibus\queues"/>
</platibus.httpserver>

Programmatic example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        var httpServerConfiguration = configuration as HttpServerConfiguration;
        if (httpServerConfiguration != null)
        {
            var path = @"C:\platibus\queues";
            var messageQueueingService = new FilesystemMessageQueueingService(path);
            httpServerConfiguration.MessageQueueingService = messageQueueingService;
        }
    }
}

A variety of message queueing service implementations are provided. See the message queueing section for configuration details.

Subscription Tracking Service

The subscription tracking service enables the HTTP server to persist subscription information so that copies of published messages can be sent to subscribers. The subscription tracking service can be specified declaratively or programmatically.

Declarative example:

<platibus.httpserver>
  <subscriptionTracking provider="Filesystem" path="C:\platibus\subscriptions"/>
</platibus.httpserver>

Programmatic example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        var httpServerConfiguration = configuration as HttpServerConfiguration;
        if (httpServerConfiguration != null)
        {
            var path = @"C:\platibus\subscriptions";
            var subscriptionTrackingService = new FilesystemSubscriptionTrackingService(path);
            httpServerConfiguration.SubscriptionTrackingService = subscriptionTrackingService;
        }
    }
}

A variety of subscription tracking service implementations are provided. See the subscription tracking section for configuration details.