MSMQ Subscription Persistence

To configure MSMQ as the subscription persistence:

endpointConfiguration.UsePersistence<MsmqPersistence>();

By default NServiceBus uses a queue called NServiceBus.Subscriptions. If not specified otherwise, all endpoints will share that queue to store subscriptions. The following warning message will get logged:

NServiceBus.Features.MsmqSubscriptionPersistence Could not find configuration section for Msmq Subscription Storage and no name was specified for this endpoint. Going to default the subscription queue

When using MSMQ Subscription Persistence on multiple endpoints running on the same machine, every endpoint must have a dedicated subscription storage queue.

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 then timeouts can be disabled:

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:

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

Samples


Last modified