MongoDB persistence for NServiceBus
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
packaging
src
.gitattributes
.gitignore
LICENSE
README.md
build.cmd
default.ps1

README.md

NServiceBus.MongoDB Build Status NuGet Status BCH compliance CodeFactor

MongoDB persistence for NServicBus 6.x

Installation

  • Get the source and build locally

or

Configuration

After adding a reference to it from your project, specify MongoDBPersistence to be used for persistence.

using NServiceBus;
using NServiceBus.MongoDB;

public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
  public void Customize(BusConfiguration configuration)
  {
    configuration.UsePersistence<MongoDBPersistence>()
        .SetDatabaseName("MyDatabase");
  }
}

This base configuration connects using NServiceBus/Persistence/MongoDB connection string in the app.config and MyDatabase as the database.

<connectionStrings>
  <add name="NServiceBus/Persistence/MongoDB" connectionString="mongodb://localhost:27017" />
</connectionStrings>

If this connection string is not found NServiceBus/Persistence is used.

<connectionStrings>
  <add name="NServiceBus/Persistence" connectionString="mongodb://localhost:27017" />
</connectionStrings>

or specify the connection string to use:

using NServiceBus;
using NServiceBus.MongoDB;

public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
  public void Customize(BusConfiguration configuration)
  {
    configuration.UsePersistence<MongoDBPersistence>()
        .SetConnectionString("mongodb://localhost:27017")
        .SetDatabaseName("MyDatabase");
  }
}

DataBus Configuration

To configure NServiceBus to use MongoDB GridFS as the persistence for DataBus use the following configuration.

using NServiceBus;
using NServiceBus.MongoDB;

public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
  public void Customize(BusConfiguration configuration)
  {
    configuration.UsePersistence<MongoDBPersistence>();
    configuration.UseDataBus<MongoDBDataBus>();
  }
}

Sagas

Saga data needs to be defined the normal way NSB requires with the additional interface IHaveDocumentVersion to work appropriately with NServiceBus.MongoDB. This interface adds two additional properties, a version number and ETag property. Alternatively you can just inherit from ContainMongoSagaData as follows:

using NServiceBus.MongoDB;
using NServiceBus.Saga;

public class MySagaData : ContainMongoSagaData
{
    public string SomeId { get; set; }

    public int Count { get; set; }
}

Samples

See Simple sample