Samples

Skip to the list of samples

The samples are designed to be highlighting how various features of NServiceBus work and how the extension points plug into other libraries and tooling.

Not Production Ready

Samples are not meant to be production ready code or to be used as-is with Particular Platform tools. They are meant to illustrate the use of the API in the simplest way possible. For this reason, these samples make certain assumptions on transport, hosting, etc. Please see the Technology choices for more details.

Not "Endpoint drop in" projects

Since the endpoint in samples have to chose specific technologies (transport, serializer, persistence etc) before using this code in production ensure the code conforms with any specific technology choices.

Downloadable and runnable

All samples have a download link that allows the sample solution to be downloaded as a zip. Once opened in Visual Studio the samples are then runnable. Note some samples may have certain infrastructure requirement, for example a database existing in a local SQL Server.

The full GitHub Repository

The samples are located in GitHub at Particular/docs.particular.net/samples and both issues and Pull Requests are accepted.

Technology Choices

Unless otherwise specified (by an individual sample) the following are the default technology choices.

C# Language Level

All samples that target NServiceBus Version 6 and higher have the C# Language Level set to 6.0 to take advantage of the newer language features.

Transport

Samples default to using the using MSMQ. See MSMQ NServiceBus Configuration to configure MSMQ in a way that is compatible with NServiceBus.

On startup each sample will create the required queues. By default the samples use the prefix samples. for all queue names. There is no process to clean up these queues, as such after running samples those queues remain in MSMQ. To clean up these queues manually use a MSMQ management tool or programmatically using the native MSMQ API

For example this PowerShell will delete all queues prefixed with private$\samples..

Add-Type -AssemblyName System.Messaging

foreach ($queue in [System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("."))
{
    if($queue.QueueName.StartsWith("private$\samples."))
    { 
        [System.Messaging.MessageQueue]::Delete($queue.Path)
    }
}

Console Hosting

Samples default to Self Hosting in a console since it is the most explicit and contains fewer moving pieces. This would not be a real choice for a production system and the other Hosting Options should be considered.

Logging

Samples default to logging at the Info level to the console. In production the preferred approach is some combination Warning and Error with a combination of targets.

Persistence

Samples default to InMemory Persistence since this has the no requirement on installed infrastructure. Since it is not durable across restarts a durable storage should be chosen for production.

Serializer

While the default serializer in NServiceBus is XML the samples default to JSON. The reason for this is that JSON is more human readable hence making samples easier to debug.

Messages definitions

In many samples Messages are defined in a shared project along with reusable helper and configuration classes. This is done so reduce the number of projects in a solution. In a real solution message definitions are most likely isolated in their own projects.

Message destinations

Many samples make use of SendLocal and sending to an endpoint directly by specify the destination using a string in code. This is done to simplify the amount of configuration in samples. In a real solution most message destination should be defined via endpoint mappings.

Container

Samples default to using the built-in container since it does not require pulling in any external NuGets. Switching to an external container will give greater flexibility in DI customizations.

Async/await

Samples by default use await and declare the surrounding method async everywhere, even if we could just return the task returned by the called API. Furthermore, ConfigureAwait(false) is not used when awaiting an asynchronous method execution. This is a conscious choice, although it is not following the best practices around async/await, to simplify readability of samples.

Samples

Azure Samples

All samples for Azure

Container Samples

All samples for Containers

Custom Checks Samples

All samples ServiceControl Custom Checks

Encryption Samples

All samples for Encryption

Hosting Samples

All samples for Hosting

Logging Samples

All samples for Logging

NHibernate Samples

All NHibernate specific samples

Outbox Samples

All Outbox relates Samples

Pipeline Samples

All samples for the Pipeline

RabbitMQ Samples

All samples for RabbitMQ

RavenDB Samples

All samples for RavenDB

Saga Samples

All samples for Sagas

  • Custom Saga Finding Logic (NHibernate)
    This sample shows how to perform custom saga finding logic based on custom query logic when the Saga storage is a relational database using NHibernate as the O/RM.
  • Custom Saga Finding Logic (RavenDB)
    This sample shows how to perform custom saga finding logic based on custom query logic when the Saga storage is RavenDB and how to use multiple Unique attributes.
  • Saga Sample
    This sample shows how build and use a saga.

Serializers Samples

All samples for Serializers

Showcase Samples

More complex samples showing many features working together

  • On Premise Show Case
    This sample implements a fictional store utilizing several features of NServiceBus.

SqlTransport Samples

All samples for the SqlTransport

Web Samples

All web related samples


Last modified 2016-01-11 14:00:26Z