Skip to content

danielHalan/NServiceBus.MongoDB

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NServiceBus.MongoDB Build Status NuGet Status

MongoDB persistence for NServicBus 5.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. All this interface adds is a version property. Alternatively you can just inherit from ContainMongoSagaData as follows:

using NServiceBus.MongoDB;
using NServiceBus.Saga;

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

    public int Count { get; set; }
}

Samples

See MongoDB persistence Sample (Special thanks to Simon Cropp for the example.)

See Simple sample

About

MongoDB persistence for NSB 5.x

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.1%
  • Smalltalk 1.4%
  • Other 0.5%