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 subscription queue can contain duplicate entries. This is by design and does not result in events being published multiple times. Subscriptrion 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 for features other than event subscriptions:

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

Samples


Last modified