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 types | Subscriptions only |
Transactions | Does not apply to subscriptions. |
Concurrency control | Does not apply to subscriptions. |
Scripted deployment | Not supported |
Installers | Subscription queues are created by installers. |
Configuration
To configure MSMQ as the subscription persistence:
endpointConfiguration.UsePersistence<MsmqPersistence>();
By default NServiceBus uses a queue called NServiceBus.
. 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
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>();