In a previous post I talked about the different ways to make sure that you have a Raven server available in order for your NServiceBus endpoints to store their data. In this post we'll look at the different options for connecting to that Raven server.

To tell NServiceBus to use Raven for persistence is a easy as calling Configure.RavenPersistence(). This is the default configuration and it uses the following conventions:

  1. If no master node is configured it will assume that a Raven server is running at http://localhost:8080, the default url for RavenDB.
  2. If a master node is configured the url used will be: http://{masternode}/:8080
  3. If a connection string named "NServiceBus.Persistence" is found the value of the connectionString attribute will be used. This pretty much give you full control over which Raven server your endpoint will use
If NServiceBus detects that any of the Raven related storage's is used, Saga, Subscription, Timeouts, etc the above will be automatically configured for you. So in essense there should be no need for you to explicitly configure Raven unless you need to override the defaults.

Overriding the defaults

There are a few situations where the default behavior might not be good enough for you.

  • You want to use your own connection string - If you're using Raven for your own data as well you might want to share connection string. You do this by using the Configure.RavenPersistence(string connectionString) signature. This tells NServiceBus to connection to the server specified in that string. The default connection string for RavenDB is "RavenDB".
  • You want to specify a explicit database name - If you want to control the database name in code instead of configuration you would use the  Configure.RavenPersistence(string connectionString, string databaseName) signature. This could be useful in multi tenant scenarios

What database will be used?

After connecting to a Raven server we need to decide which actual database to use. Unless we find a default database specified in the connection string NServiceBus will use the endpoint name as the database name. So if your endpoint is named "MyServer" the database name will be "MyServer". Each endpoint will have a separate database unless you explicitly override using the connection string. RavenDB will automatically create the database if it doesn't already exist.

A detailed explanation of the endpoint name concept can be found here.

Can I use the IDocumentStore used by NServiceBus for my own data?

No the Raven client is merged and internalized into the NServiceBus assemblies so if you want to use Raven for your own purposes you need to reference the Raven client and setup your own document store.

How do I look at the data?

Just open a web browser and type the url if the Raven server, this will open up the Raven DB management studio.