MSMQ Subscription Persistence

Project Hosting | Nuget: NServiceBus (Version: 6.x)
Storing subscriptions in MSMQ is not suitable when endpoints are scaled-out, because the subscription queue cannot be shared among multiple endpoints, especially if the endpoints are running on different machines.

To configure MSMQ as the subscription persistence:

Edit
endpointConfiguration.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:

Edit
<configuration>
  <configSections>
    <section name="MsmqSubscriptionStorageConfig" 
             type="NServiceBus.Config.MsmqSubscriptionStorageConfig, NServiceBus.Core" />
  </configSections>
  <MsmqSubscriptionStorageConfig Queue="YourQueue" />
</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 then timeouts can be disabled:

Edit
endpointConfiguration.DisableFeature<TimeoutManager>();
endpointConfiguration.UsePersistence<MsmqPersistence>();
If timeouts are disabled then features such as Delayed Retries and Saga timeouts cannot be used.

Another approach is to use a different persistence for features different than event subscriptions:

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

Last modified