In RavenDB 3.5, the client implementation of distributed transactions contains a bug that could cause an endpoint to lose data under rare conditions. If RavenDB is configured to enlist in distributed transactions with RavenDB 3.5, read DTC not supported for RavenDB Persistence.
Using RavenDB version 5 and higher in a cluster configuration with multiple nodes is only supported from version 7 or higher of the NServiceBus.RavenDB persistence package. For more information, read cluster configuration with multiple nodes.
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.
When the RavenDB DocumentStore
is created by the user at endpoint configuration time, it's important to dispose it by calling the Dispose()
method, before shutting down the endpoint process.
External shared store at initialization
To use an external DocumentStore
, but defer its creation until NServiceBus initializes, a Func
can be provided which will allow the DocumentStore
to be created with access to the ReadOnlySettings
. 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.
.
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 found in ReadOnlySettings
, 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(
readOnlySettings =>
{
subscriptionStore = new DocumentStore();
// configure documentStore here
return subscriptionStore;
});
persistence.UseDocumentStoreForSagas(
readOnlySettings =>
{
sagaStore = new DocumentStore();
// configure documentStore here
return sagaStore;
});
persistence.UseDocumentStoreForTimeouts(
readOnlySettings =>
{
timeoutStore = new DocumentStore();
// configure documentStore here
return timeoutStore;
});
persistence.UseDocumentStoreForGatewayDeduplication(
readOnlySettings =>
{
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:/
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.