For those users requiring their data to be persisted in a relational database we provide a separate assembly that adds support for NHibernate based storages.
If you downloaded NServiceBus from this site (rather than via NuGet) you will have to add a reference to NServiceBus.NHibernate.dll (which can be found in the binaries folder). You also need to download and reference version 3.3.0.4000 of NHibernate.
If you are using NuGet the only thing you need to do is to install NServiceBus.NHibernate, like this:
PM> Install-Package NServiceBus.NHibernate
This will automatically setup all the dependencies needed for you and is the recommended way of using the NHibernate support.
Subscriptions
To have your subscriptions stored using NHibernate you have to use the following configuration.
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server,IWantCustomInitialization { public void Init() { Configure.With() .DefaultBuilder() .DBSubcriptionStorage(); } }
NServiceBus will then pickup the connection setting from your app.config. Below is an example of this (using SqlLite):
<DBSubscriptionStorageConfig UpdateSchema="true"> <NHibernateProperties> <add Key="connection.provider" Value="NHibernate.Connection.DriverConnectionProvider"/> <add Key="connection.driver_class" Value="NHibernate.Driver.SQLite20Driver"/> <add Key="connection.connection_string" Value="Data Source=.\DBFileNameFromAppConfig.sqlite;Version=3;New=True;"/> <add Key="dialect" Value="NHibernate.Dialect.SQLiteDialect"/> </NHibernateProperties> </DBSubscriptionStorageConfig>
More info about the available properties here
Sagas
To have your sagas stored using NHibernate you have to use the following configuration.
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server,IWantCustomInitialization { public void Init() { Configure.With() .DefaultBuilder() .NHibernateSagaPersister(); } }
An example configuration is found below:
<NHibernateSagaPersisterConfig UpdateSchema="true"> <NHibernateProperties> <add Key="connection.provider" Value="NHibernate.Connection.DriverConnectionProvider"/> <add Key="connection.driver_class" Value="NHibernate.Driver.SQLite20Driver"/> <add Key="connection.connection_string" Value="Data Source=.\DBFileNameFromAppConfig.sqlite;Version=3;New=True;"/> <add Key="dialect" Value="NHibernate.Dialect.SQLiteDialect"/> </NHibernateProperties> </NHibernateSagaPersisterConfig>
Timeouts
To have the timeout manager store its timeouts using NHibernate you have to use the following configuration (SqlServer2008 in this case). Note that this is valid from version 3.2.3 and on.
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server,IWantCustomInitialization { public void Init() { Configure.With() .DefaultBuilder() .UseNHibernateTimeoutPersister(); } }
<TimeoutPersisterConfig UpdateSchema="true"> <NHibernateProperties> <add Key="connection.provider" Value="NHibernate.Connection.DriverConnectionProvider"/> <add Key="connection.driver_class" Value="NHibernate.Driver.Sql2008ClientDriver"/> <add Key="connection.connection_string" Value="Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True"/> <add Key="dialect" Value="NHibernate.Dialect.MsSql2008Dialect"/> </NHibernateProperties> </TimeoutPersisterConfig>
