Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Configuration order for persistence

Component: NServiceBus
NuGet Package: NServiceBus (9.1)

When using different persistence options for storage types, the configuration order is important. When specifying multiple persistence options for the same storage type, the last-configured option will be used. Using the generic UsePersistence<TPersistenceOption> (without specifying a storage type) applies the persistence to all its supported storage types.

Example 1

In this example, RavenDB persistence is used for all storage types as it overwrites the configuration for the outbox and subscription storage types.

endpointConfiguration.UsePersistence<NHibernatePersistence, StorageType.Outbox>();

// This one will override the above settings
endpointConfiguration.UsePersistence<RavenDBPersistence>();

Example 2

To avoid overwriting, all storage types can be explicitly configured using the UsePersistence<TPersistenceOption, TStorageType> API.

endpointConfiguration.UsePersistence<NHibernatePersistence, StorageType.Outbox>();

endpointConfiguration.UsePersistence<RavenDBPersistence, StorageType.Sagas>();
endpointConfiguration.UsePersistence<RavenDBPersistence, StorageType.Subscriptions>();

Example 3

Instead of explicitly defining all storage types, the generic persistence option can specified before the explicit overwrites. In this example, RavenDB persistence will be used for all storage types except for the outbox and subscriptions.

endpointConfiguration.UsePersistence<RavenDBPersistence>();

endpointConfiguration.UsePersistence<NHibernatePersistence, StorageType.Outbox>();