Skip to content

3.6 Message Journaling

Jesse Sweetland edited this page Jun 9, 2017 · 8 revisions

A Platibus bus may use a message journal to store copies of all messages that are sent, received, or published by that instance. Message journals implement the IMessageJournal interface, which specifies methods to independently handle sent, received, and published messages. The base distribution packages provide a number of implementations out of the box.

The message journal is optional and is specified via a nested <journaling> configuration element or by setting the MessageJournal property on the configuration object via a configuration hook.

SQL Message Journal

The SQLMessageJournal writes journaled messages in table named PB_MessageJournal in a SQL database. It accepts a single (required) configuration parameter indicating the name of the connection string used to create connections to the target database.

Declarative configuration example:

   <connectionStrings>
       <add name="Platibus" connectionString="Data Source=(LocalDB)\MSSQLLocalDB; Integrated Security=true; Initial Catalog=Platibus" providerName="System.Data.SqlClient"/>
   </connectionStrings>
   <journaling provider="SQL" connectionName="Platibus" />

Programmatic configuration example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        var httpServerConfiguration = configuration as HttpServerConfiguration;
        if (httpServerConfiguration != null)
        {
            var connectionStringSettings = new ConnectionStringSettings 
            {
                ProviderName = "System.Data.SqlClient",
                ConnectionString = "Data Source=(LocalDB)\MSSQLLocalDB; Integrated Security=true; Initial Catalog=Platibus"
            }
            httpServerConfiguration.MessageJournal = new SQLMessageJournal(connectionStringSettings);
        }
    }
}

SQLite Message Journal

The Platibus.SQLite package offers a slight variation of the SQLMessageJournal that uses a local SQLite database file to store journaled messages. This can be advantageous if SQL storage and query functionality are desired but local storage is needed to avoid a single point of failure (i.e. a remote SQL server instance goes down or cannot be reached).

The SQLiteMessageJournal requires a single optional parameter indicating the path in which the SQLite database files should be created that defaults to the path platibus/journal relative to the app domain base directory.

Declarative configuration example:

   <journaling provider="SQLite" path="C:\platibus\queues" />

Programmatic configuration example:

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

MongoDB Message Journal

The MongoDBMessageJournal writes journaled messages in collection named platibus.messageJournal in a MongoDB database. It accepts a single (required) configuration parameter indicating the name of the connection string used to create connections to the target database.

Declarative configuration example:

   <connectionStrings>
       <add name="Platibus" connectionString="mongodb://localhost:27017/mydatabase"/>
   </connectionStrings>
   <journaling provider="MongoDB" connectionName="Platibus" />

Programmatic configuration example:

public class ConfigurationHook : IConfigurationHook
{
    public void Configure(PlatibusConfiguration configuration)
    {
        var httpServerConfiguration = configuration as HttpServerConfiguration;
        if (httpServerConfiguration != null)
        {
            var connectionStringSettings = new ConnectionStringSettings 
            {
                ConnectionString = "mongodb://localhost:27017/mydatabase"
            }
            httpServerConfiguration.MessageJournalingService = new MongoDBMessageJournal(connectionStringSettings);
        }
    }
}