The Learning Persistence simulates saga persistence infrastructure by storing data in the local file system. All files and directories are relative to the current project directory.
Added in NServiceBus 6.3.
Some recommended use cases are:
- Learning/Experimenting with NServiceBus features.
- Building a spike or demo.
- Reproducing a bug that is not related to a production transport, for example when raising a support case.
By default all data is stored in a
. directory that exists at AppDomain.CurrentDomain.BaseDirectory.
To configure the storage location:
var persistence = endpointConfiguration.UsePersistence<LearningPersistence>(); persistence.SagaStorageDirectory("PathToStoreSagas");
Each saga will be stored a sub-directory matching the saga type name with the saga data being serialized into a
. file named based on the saga Id.
When simultaneously handling messages, conflicts may occur. See below for examples of the exceptions which are thrown. Saga concurrency explains how these conflicts are handled, and contains guidance for high-load scenarios.
System.IO.IOException: The file 'S:\.sagas\OrderSaga\944b7efb-7146-adf1-d6ae-968f0d7757fa.json' already exists.
Learning persistence uses file locks when updating or deleting saga data. The effect is similar to optimistic concurrency control with the difference that failure will occur when reading the saga data, before the handler is invoked.
The process cannot access the file 'S:\.sagas\OrderSaga\a71d248d-0d94-e0bf-3673-361dbd3ec026.json' because it is being used by another process.