Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

MSMQ Subscription Persistence

NuGet Package: NServiceBus.Transport.Msmq (1.x)
Target Version: NServiceBus 7.x

The MSMQ Subscription storage can be used to enable publish/subscribe with MSMQ without the need for any additional persister.

Persistence at a glance

For a description of each feature, see the persistence at a glance legend.

Feature
Supported storage typesSubscriptions only
TransactionsDoes not apply to subscriptions.
Concurrency controlDoes not apply to subscriptions.
Scripted deploymentNot supported
InstallersSubscription queues are created by installers.

Configuration

To configure MSMQ as the subscription persistence:

endpointConfiguration.UsePersistence<MsmqPersistence>();

If the subscription storage is not specified, NServiceBus uses a queue called [EndpointName].Subscriptions. This is to avoid all endpoints deployed on the same server from having to share the same queue to store subscriptions. When a subscription queue is not specified and the default queue is being used, the following message will get logged:

The queue used to store subscriptions has not been configured, the default 'NServiceBus.Subscriptions' will be used.

Versions 5.x and Versions 6.x of NServiceBus used a default queue called NServiceBus.Subscriptions. An exception is thrown on startup if this queue is detected. Either specify the subscription queue explicitly or move the subscription messages to the new default queue to avoid message loss.

In order to specify a different queue, use the code API or specify a configuration section.

Via code

Call the following code API passing the subscription queue to use:

var persistence = endpointConfiguration.UsePersistence<MsmqPersistence>();
persistence.SubscriptionQueue("YourEndpointName.Subscriptions");

Via app.config

Add the following configSections and subsequent config entry:

<configuration>
  <configSections>
    <section name="MsmqSubscriptionStorageConfig" 
             type="NServiceBus.Config.MsmqSubscriptionStorageConfig, NServiceBus.Core" />
  </configSections>
  <MsmqSubscriptionStorageConfig Queue="YourEndpointName.Subscriptions" />
</configuration>

Timeouts persistence

MsmqPersistence provides persistence only for storing event subscriptions. By default, NServiceBus also requires a timeout persistence, which is used by delayed retries, saga timeouts and for delayed delivery.

If none of these features are used, timeouts can be disabled:

endpointConfiguration.DisableFeature<TimeoutManager>();
endpointConfiguration.UsePersistence<MsmqPersistence>();

Another approach is to use a different persistence storage types for features other than subscriptions like shown below:

endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.Sagas>();
endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.Timeouts>();
endpointConfiguration.UsePersistence<MsmqPersistence, StorageType.Subscriptions>();

Samples