Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Connection Options

The following sections outline various ways to connect to the RavenDB server. Specifying an external shared store (providing a fully configured RavenDB DocumentStore instance) is preferred so that the configuration of the DocumentStore is not obscured.

External shared store at initialization

To use an external DocumentStore, but defer its creation until NServiceBus initializes, a custom factory delegate can be provided which will allow the DocumentStore to be created with access to the settings and the dependency injection container. This gives the ability to configure the document store based on conventions derived from endpoint data present in the settings object. For example, the DocumentStore instance can be configured to use the Endpoint Name as its database name by accessing readOnlySettings.EndpointName().

DocumentStore documentStore;
var persistence = endpointConfiguration.UsePersistence<RavenDBPersistence>();
persistence.SetDefaultDocumentStore(
    readOnlySettings =>
    {
        documentStore = new DocumentStore();
        // configure documentStore here
        return documentStore;
    });

External store at initialization for a specific persister

A DocumentStore can be created at initialization time, with access to endpoint settings and the dependency injection container, for usage in a specific persister (e.g. timeouts) by using the following code:

//TODO: instances of DocumentStore should be disposed of at endpoint cleanup time
DocumentStore subscriptionStore;
DocumentStore sagaStore;

var persistence = endpointConfiguration.UsePersistence<RavenDBPersistence>();
persistence.UseDocumentStoreForSubscriptions(
    readOnlySettings =>
    {
        subscriptionStore = new DocumentStore();
        // configure documentStore here
        return subscriptionStore;
    });
persistence.UseDocumentStoreForSagas(
    readOnlySettings =>
    {
        sagaStore = new DocumentStore();
        // configure documentStore here
        return sagaStore;
    });

External shared store for all persisters

The RavenDB DocumentStore instance can be provided directly to NServiceBus to use for all persisters. This enables sharing the same application database for NServiceBus data as well.

var documentStore = new DocumentStore();
// configure documentStore here
var persistence = endpointConfiguration.UsePersistence<RavenDBPersistence>();
persistence.SetDefaultDocumentStore(documentStore);

External store for a specific persister

An externally created DocumentStore instance can be used for a specific persister (e.g. timeouts) by using the following code:

var documentStore = new DocumentStore();
// configure documentStore here
var persistence = endpointConfiguration.UsePersistence<RavenDBPersistence>();
persistence.UseDocumentStoreForSubscriptions(documentStore);
persistence.UseDocumentStoreForSagas(documentStore);

Default

By default, a DocumentStore is created that connects to http://localhost:8080 and uses the endpoint name as its database name. This default connection is used for all the persisters.

Database used

After connecting to a RavenDB server, decide which database to use. Unless NServiceBus finds a default database specified in the connection string, NServiceBus uses the endpoint name as the database name. This means that if the endpoint is named MyServer, the database name will be MyServer. Each endpoint has a separate database unless explicitly overridden via the connection string.

See also How to specify endpoint name.

Database creation

Prior to RavenDB version 4.0, RavenDB automatically creates the database if it doesn't already exist. This is no longer the case in RavenDB versions 4.0 and above.

Samples