MSMQ Subscription Persistence

Source
NuGet Package NServiceBus (5.x)
Standard support for version 5.x of NServiceBus has expired. For more information see our Support Policy.

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

This can only be used to store subscriptions. To use sagas, timeouts, deferred messages, or the Outbox, a different persister is required.

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

MSMQ Persistence does not support scaled-out publishers. This is because the MSMQ storage is local to the machine, and a subscription message will only be delivered to one endpoint instance of a given logical endpoint, and only that instance will be able to update its information, while other instances remain unaware of the new subscriber.
The subscription queue can contain duplicate entries. This is by design and does not result in events being published multiple times. Subscription entries are added for each subscription request received. After a publisher restarts, the subscription queue state will be rewritten and deduplicated.
Storing subscriptions in MSMQ must not be used when scaling out across multiple machines or running side-by-side on the same machine. The subscription queue cannot be shared among multiple endpoints instances for the same endpoint.

To configure MSMQ as the subscription persistence:

busConfiguration.UsePersistence<MsmqPersistence>();

When using MSMQ subscription persistence, the default queue to store the subscription messages is NServiceBus.Subscriptions. It is important to override this queue name for each endpoint to avoid sharing the same subscription queue for different endpoints running on the same machine.

To specify a different subscriptions queue, add the following configuration as shown below:

<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:

busConfiguration.DisableFeature<TimeoutManager>();
busConfiguration.UsePersistence<MsmqPersistence>();
If timeouts are disabled, features such as delayed retries and saga timeouts cannot be used.

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

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

Samples


Last modified