Getting Started
Architecture
Particular Service Platform
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(
    (settings, builder) =>
    {
        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;
DocumentStore timeoutStore;
DocumentStore gatewayStore;

var persistence = endpointConfiguration.UsePersistence<RavenDBPersistence>();
persistence.UseDocumentStoreForSubscriptions(
    (settings, builder) =>
    {
        subscriptionStore = new DocumentStore();
        // configure documentStore here
        return subscriptionStore;
    });
persistence.UseDocumentStoreForSagas(
    (settings, builder) =>
    {
        sagaStore = new DocumentStore();
        // configure documentStore here
        return sagaStore;
    });
persistence.UseDocumentStoreForTimeouts(
    (settings, builder) =>
    {
        timeoutStore = new DocumentStore();
        // configure documentStore here
        return timeoutStore;
    });
persistence.UseDocumentStoreForGatewayDeduplication(
    (settings, builder) =>
    {
        gatewayStore = new DocumentStore();
        // configure documentStore here
        return gatewayStore;
    });

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);
persistence.UseDocumentStoreForGatewayDeduplication(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