Solutions    |    Downloads    |    License    |    Documentation    |    Training    |    Support    |    Customers    |    About Us

Relational Persistence Using NHibernate

Last Updated: Nov 27, 2012 05:27PM IST

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>
About NServiceBus    |    Contact Us    |    Privacy    |    Follow us on:   
Copyright 2010-2013 NServiceBus. All rights reserved
NSB_Y@yahoo.com
http://assets1.desk.com/r1046ffeaa2233e531563a32d7edef6677d8a78b5/javascripts/
nservicebus
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
true
Invalid characters found
/customer/portal/articles/autocomplete
There was an error contacting Get Satisfaction
View All
0
discussions
replies
Questions
Ideas
Problems
Praise