Coder Social home page Coder Social logo

tonyeung / nservicebus.persistence.mongodb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from particularlabs/nservicebus.persistence.mongodb

0.0 2.0 0.0 1.08 MB

MongoDB Persistence for NServiceBus v5

Batchfile 0.80% PowerShell 2.81% C# 96.39%

nservicebus.persistence.mongodb's Introduction

NServiceBus.Persistence.MongoDb Build status NuGet version##

NServiceBus is the most developer-friendly service bus for .NET. This package includes MongoDB persistence implementations for:

  • Timeouts
  • Subscriptions
  • Sagas
  • DataBus

All the boilerplate code is encapsulated in the implementation details which we took care of.
No leaking abstractions, code against the well known Api.

Install

To enable MongoDb persistence capability install NServiceBus.Persistence. MongoDb
package in your NServiceBus service host project. At the moment there are 2 options

  1. NuGet package
    • Package Manager Console: Install-Package NServiceBus.Persistence.MongoDb
  2. From source
    • git clone https://github.com/tekmaven/NServiceBus.Persistence.MongoDb
    • .\build.cmd

Configuration

The minimal configuration you need to get up and running in 3 steps:

1 Instruct the service host to use MongoDb persistence

using NServiceBus;
using NServiceBus.Persistence.MongoDB;

namespace Example
{
    public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
    {
        public void Customize(BusConfiguration configuration)
        {
            configuration.UsePersistence<MongoDbPersistence>();
        }
    }
}

2 Add in the app.config following

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

3 Hit F5. Yes, is that simple.

When default configuration is not an option

The persistence configuration model provides a reach API. This enables to override the default
connection string name by calling .SetConnectionStringName(string) extension method.

config
	.UsePersistence<MongoDbPersistence>()
	.SetConnectionStringName("SharedConnectionString");

If you are resolving your configuration setting from a different source at run-time which is
very common in cloud based deployments. Then you can use .SetConnectionString(string)
to provide it.

config
	.UsePersistence<MongoDbPersistence>()
	.SetConnectionString("mongodb://localhost/databaseName");

Saga definition guideline##

In order to get Sagas working correctly you need to enforce following

  • your saga state should implement IContainSagaData
  • requires a property Version decorated with attribute [DocumentVersion]
  • the correlation id property should be decorated with attribute [Unique]

Here is an example

public class OrderBillingSagaData : IContainSagaData
{
    [Unique]
    public string OrderId { get; set; }

    [DocumentVersion]
    public int Version { get; set; }

    public bool Canceled { get; set; }

    public Guid Id { get; set; }
    public string Originator { get; set; }
    public string OriginalMessageId { get; set; }
} 

Dealing with concurrency

The key concurrency safeguards that sagas guarantee depend heavily on the underlying data store.
The two specific cases that NServiceBus relies on the underling data store are concurrent access to
non-existing saga instances
and concurrent access to existing saga instances.

Here is how we deal with them

Concurrent access to non-existing saga instances. The persister uses MongoDb's Unique Indexes
to ensure only one document can contain the unique data.

Concurrent access to existing saga instances. The persister uses a document versioning
scheme built on top of MongoDb's findAndModify command to atomically update the existing
persisted data only if it has not been changed since it was retrieved. Since the update
is atomic, it will ensure that if there are multiple simultaneous updates to a saga, only one
will succeed.

DataBus

Do you use DataBus? We also supply an implimentation that is backed with MongoDB's GridFS. To configure, just add this line to your busConfiguration:

using NServiceBus;
using NServiceBus.Persistence.MongoDB;

namespace Example
{
    public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
    {
        public void Customize(BusConfiguration configuration)
        {
            configuration.UsePersistence<MongoDbPersistence>();
            configuration.UseDataBus<MongoDbDataBus>(); //add this line!
        }
    }
}

Thanks to our contributors

@ruslanrusu
CRuppert

nservicebus.persistence.mongodb's People

Contributors

cruppert avatar ruslander avatar tekmaven avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.