Skip to content

3. Configuration

Jesse Sweetland edited this page Sep 27, 2015 · 20 revisions

Platibus can be configured programmatically, declaratively, or with a mixture of both styles. In any case, the objective is to initialize an IPlatibusConfiguration implementation that will be passed to the Platibus.Bus constructor. This interface provides access to all of the configuration and dependencies needed by the bus itself.

Additional configuration may be required to configure the bus host itself. In general, these configurations inherit from and extend IPlatibusConfiguration to provide the additional configuration details for the host. Host-specific configuration is described in more detail in the following sections:

  1. HTTP Server Configuration
  2. IIS Configuration
  3. RabbitMQ Configuration
  4. Message Queueing
  5. Subscription Tracking

Common Bus Configuration

The Platibus.Bus instance performs the core functions of sending and handling messages. In order to do so, there is a core set of configuration needed by the bus regardless of how it is hosted.

Reply Timeout

When a message is sent the bus creates and stores a reference to an observable ISentMessage object for that message. This object reference is held until all replies to that message are received or a reply timeout occurs. The IPlatibusConfiguration.ReplyTimeout property specifies the maximum amount of time that the sent message reference will be held awaiting a reply.

Declarative example:

<!-- HTTP configuration section -->
<platibus.http replyTimeout="00:05:00">
  <!-- Other configuration ... -->
</platibus.http>

Programmatic example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        configuration.ReplyTimeout = TimeSpan.FromMinutes(5);
    }
}

Serialization Service

The serialization service is specified via the IPlatibusConfiguration.SerializationService property. This object provides ISerializer implementations based on MIME content types. The default implementation, Platibus.Serialization.DefaultSerializationService, provides out-of-the-box support for text/plain, application/json, application/xml, and application/octet-stream content types. Support for additional content types can be added via the DefaultSerializationProvider.Add method.

There is currently no support for declaratively specifying the serialization service. However, a Platibus.IConfigurationHook can be used to override the default serialization service in the PlatibusConfiguration that is generated from the declarative configuration before the bus is initialized.

Programmatic example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        var serializationService = DefaultSerializationService();
        // Override the default Newtonsoft Json.Net based serializer
        serializationService.Add("application/json", new DataContractJsonSerializer());
        configuration.MessageNamingService = serializationService;
    }
}

Message Naming Service

To facilitate serialization and deserialization, message object types are assigned a message name that serves as a platform-agnostic type identifier. On the sending side, the message object's type is mapped to a message name which is transmitted to the recipient in the message headers. On the receiving side the message name is mapped onto a suitable type (if applicable) to aid in deserializing the message content. The message naming service is the component that the bus uses to map message object types onto message names and vice-versa.

The message naming service is specified by the IPlatibusConfiguration.MessageNamingService property. The default implementation, Platibus.DefaultMessageNamingService, simply uses the full name of the message type as the message name. An alternate implementation, Platibus.DataContractMessageNamingService, will use the XML qualified name of the data contract for message types decorated with System.Runtime.Serialization.DataContractAttribute and will fall back to the full type name for message types that are not data contracts.

There is currently no support for declaratively specifying the message naming service. However, a Platibus.IConfigurationHook can be used to override the default message naming service in the PlatibusConfiguration that is generated from the declarative configuration before the bus is initialized.

Programmatic example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        var namingService = new DataContractMessageNamingService();
        configuration.MessageNamingService = namingService;
    }
}

Message Journaling Service

The message journaling service is an optional component that can be used to track the sending and receipt of messages for diagnostics, compliance, or other purposes. It is specified via the IPlatibusConfiguration.JournalingService property.

The message journaling service can be specified declaratively by adding a <messageJournaling> element to the declarative configuration section or programmatically by setting the value of the PlatibusConfiguration.MessageJournalingService property from a Platibus.IConfigurationHook.

Declarative example:

<messageJournaling provider="Filesystem" path="C:\platibus\journal"/>

Programmatic example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        var path = @"C:\platibus\journal";
        var journalingService = new FilesystemMessageJournalingService(path);
        configuration.MessageJournalingService = journalingService;
    }
}

Because journaling is optional, there is no default configuration, meaning journaling is disabled by default. The examples above demonstrate an implementation has been provided that stores copies of the messages that are send or received as files in a specified base directory. The path attribute is optional and will default to a folder named platibus\journal under the app domain base directory.

Topics

Named topics must be declared before messages can be published to them. This ensures that messages are published to valid topics and enables remote systems to query for lists of topics to which they can subscribe. Topics can be added to the <topics> element of the declarative configuration section or by adding topics to the PlatibusConfiguration via the AddTopic method from an IConfigurationHook.

Declarative example:

<topics>
    <add name="OrderEvents"/>
    <add name="CustomerEvents"/>
</topics>

Programmatic example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        configuration.AddTopic("OrderEvents");
        configuration.AddTopic("CustomerEvents");
    }
}

Endpoints

Endpoints describe Platibus instances to which messages can be sent and from which messages can be received by subscription. Each endpoint must be assigned a unique name that is used elsewhere in the configuration to refer to the endpoint (e.g. send rules and subscription rules).

Endpoint hosts may require authentication in order to send messages. In these cases the endpoint configuration should specify the type of credentials required and additional details (username, password, etc.) as applicable. Currently, only basic authentication and Windows authentication are supported.

Endpoints can be added to the <endpoints> element of the declarative configuration section or by adding endpoints to the PlatibusConfiguration via the AddEndpoint method from an IConfigurationHook.

Declarative example:

<endpoints>
    <add name="provisioning-system" address="http://prov.example.com/platibus" 
         credentialType="Basic" username="user" password='trustno1'/>
    <add name="crm-system" address="http://crm.example.com/platibus" credentialType="Windows" />
</endpoints>

Programmatic example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        configuration.AddEndpoint("provisioning-system",
            new Endpoint(new Uri("http://provisioning.example.com/platibus"),
            new BasicAuthCredentials("user", "trustno1")));
        configuration.AddEndpoint("crm-system",
            new Endpoint(new Uri("http://crm.example.com/platibus"), 
            new DefaultNetworkCredentials()));
    }
}

Send Rules

Subscription Rules

Configuration Hooks