RavenDB Persistence

Project Hosting: https://github.com/Particular/NServiceBus.RavenDB
Nuget Package: NServiceBus.RavenDB (Version: 4.x - N)
Target NServiceBus Version: 6.x

Uses the RavenDB document database for storage.

Connection options for RavenDB

There are a variety of options for configuring the connection to a RavenDB Server. See RavenDB Connection Options for more details.

Shared session

NServiceBus supports sharing the same RavenDB document session between Saga persistence, Outbox persistence, and business data, so that a single transaction can be used to persist the data for all three concerns atomically.

Shared session is only applicable to Saga and Outbox storage. It can be configured via

var documentStore = new DocumentStore();
// configure documentStore here
var persistence = endpointConfiguration.UsePersistence<RavenDBPersistence>();
persistence.UseSharedAsyncSession(() =>
    var session = documentStore.OpenAsyncSession();
    // customize session here
    return session;

This optionally allows customization of the document session that is created for Saga, Outbox, and handler logic to share.

The session that is created is then made available to handler logic, although the method differs based on NServiceBus version:

public class MyMessageHandler :
    public Task Handle(MyMessage message, IMessageHandlerContext context)
        var doc = new MyDocument();

        var ravenSession = context.SynchronizedStorageSession.RavenSession();
        return ravenSession.StoreAsync(doc);

Distributed Transaction Coordinator settings

The RavenDB client requires a unique Guid to identify it to the Distributed Transaction Coordinator, and a method of storing DTC transaction recovery information in the case of process faults. By default, NServiceBus uses IsolatedStorageTransactionRecoveryStorage as its transaction recovery storage. Under certain high-load situations, this has been known to result in a TransactionAbortedException or IsolatedStorageException.

In order to set DTC settings that are safe for production use, refer to Setting RavenDB DTC settings manually.

Viewing the data

Open a web browser and type the URL of the RavenDB server. This opens the RavenDB Studio.


Related Articles

Last modified