Configuration order for persistence

Component: NServiceBus
NuGet Package NServiceBus (7.x)

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 GatewayDeduplication storage types.

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

endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.GatewayDeduplication>();

// 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<InMemoryPersistence, StorageType.GatewayDeduplication>();

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

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 GatewayDeduplication.

endpointConfiguration.UsePersistence<RavenDBPersistence>();

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

endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.GatewayDeduplication>();

Last modified