-
Notifications
You must be signed in to change notification settings - Fork 7
3.7 Subscription Tracking
HTTP based hosts and transports (HttpServer
, PlatibusHttpModule
, PlatibusHttpHandler
, and PlatibusOwinMiddleware
) use a subscription tracking service to record the URIs and expiration dates of subscriptions created via POST requests to a topic
resource. (For example, a POST request to the URI topic/allevents/subscriber?uri=http%3A%2F%2Fexample.com%2Fplatibus&ttl=300
will create a new tracked subscription for a subscriber at URI http://example.com/platibus that must be renewed every 5 minutes.) When messages are published, the HTTP transport service queries the subscription tracking service for all of the active (non-expired) subscriptions and POSTs the published message to each of them.
Subscription tracking services implement the ISubscriptionTrackingService interface, which specifies methods for creating, deleting, and querying subscriptions. The base distribution packages provide a number of implementations out of the box.
The InMemorySubscriptionTrackingService stores subscriptions in memory. This is a useful configuration for testing or for situations in which subscriptions do not need to survive a process crash or restart.
Declarative configuration example:
<subscriptionTracking provider="InMemory" />
Programmatic configuration example:
public class ConfigurationHook : IConfigurationHook
{
public void Configure(PlatibusConfiguration configuration)
{
var httpServerConfiguration = configuration as HttpServerConfiguration;
if (httpServerConfiguration != null)
{
httpServerConfiguration.SubscriptionTrackingService = new InMemorySubscriptionTrackingService();
}
}
}
The FilesystemSubscriptionTrackingService stores subscription information on the filesystem so that the they will survive a process crash or restart. It accepts a single (optional) configuration parameter indicating the path in which subscriptions should be written that defaults to the path platibus/subscriptions
relative to the app domain base directory.
Declarative configuration example:
<subscriptionTracking provider="Filesystem" path="C:\platibus\subscriptions" />
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\subscriptions");
httpServerConfiguration.SubscriptionTrackingService = new FilesystemSubscriptionTrackingService(path);
}
}
}
The SQLSubscriptionTrackingService stores subscription in table named PB_Subscriptions
in a SQL database so that they can be shared across servers and survive a process crash or restart. 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>
<subscriptionTracking 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.SubscriptionTrackingService = new SQLSubscriptionTrackingService(connectionStringSettings);
}
}
}
The Platibus.SQLite
package offers a slight variation of the SQLSubscriptionTrackingService that uses a local SQLite database file to subscriptions. 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 SQLiteSubscriptionTrackingService requires a single optional parameter indicating the path in which the SQLite database files should be created that defaults to the path platibus/subscriptions
relative to the app domain base directory.
Declarative configuration example:
<subscriptionTracking 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\subscriptions");
httpServerConfiguration.SubscriptionTrackingService = new SQLiteSubscriptionTrackingService(path);
}
}
}
The MongoDBSubscriptionTrackingService stores subscription in table named platibus.subscriptions
in a MongoDB database so that they can be shared across servers and survive a process crash or restart. 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>
<subscriptionTracking 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.SubscriptionTrackingService = new MongoDBSubscriptionTrackingService(connectionStringSettings);
}
}
}
Subscriptions to instances hosted by RabbitMQHost are created by joining a new subscriber queue to the fan out exchange created for a topic. Copies of messages sent to the exchange will automatically be placed in the joined queues and do not require a subscription tracking from within the bus instance itself.