Book Image

Learning NServiceBus - Second Edition

By : David Boike
Book Image

Learning NServiceBus - Second Edition

By: David Boike

Overview of this book

Table of Contents (18 chapters)
Learning NServiceBus Second Edition
About the Author
About the Reviewers

Getting the code

We will be covering a lot of information very quickly in this chapter, so if you see something that doesn't immediately make sense, don't panic! Once we have the basic example in place, we will look back and explain some of the finer points in more detail.

To get the actual NServiceBus binaries, we will use NuGet exclusively, but before we get started on our first project, we should download and run the installer for the entire Particular Service Platform, which will ensure that your machine is set up properly to run NServiceBus solutions. Additionally, the platform installer will install several other helpful applications that will assist in your NServiceBus development, which we will cover in more detail in Chapter 8, The Service Platform.

Download the installer from and run it on your machine. The following screenshot depicts the applications installed by the platform installer:

You should select all the options that are available to you. There are two options for ServiceMatrix because of differences in how Visual Studio handles add-ins between Visual Studio 2012 and 2013, so you can install whichever matches the version of Visual Studio you use.

In addition to the Service Platform apps, the installer does several things to get your system ready to go:

  • Microsoft Message Queueing (MSMQ): This is installed on your system if it isn't already. MSMQ is the default message transport that provides the durable, transactional messaging that is at the core of NServiceBus (this is only one messaging transport supported by NServiceBus. We will learn about others in Chapter 4, Hosting).

  • Distributed Transaction Coordinator (DTC): This is configured on your system. It will coordinate transactional data access between resources (such as MSMQ) that support it in order to guarantee that messages are processed once and only once.

  • NServiceBus performance counters: These are added to help you monitor NServiceBus' performance.

Now that our system is ready to go, we can get started building our first solution by pulling in the NServiceBus NuGet packages.

NServiceBus NuGet packages

Once your computer has been prepared for the first time, you have to include NServiceBus within an application using the NuGet packages.

There are three core NServiceBus NuGet packages:

  • NServiceBus: This package contains the core assembly with most of the code that drives NServiceBus, except for the hosting capability. This is the package we will reference when we host NServiceBus within our own process, such as in a web application.

  • NServiceBus.Host: This package contains the service host executable. With the host, we can run an NServiceBus service endpoint from the command line during development, and then install it as a Windows service for production use.

  • NServiceBus.Testing: This package contains a framework used to unit-test NServiceBus endpoints and sagas. We will cover this in more detail in Chapter 6, Sagas.

If you try installing the NuGet packages first, they will attempt to detect this and direct you to download the entire Particular Service Platform from the website. Without running the installer, it's difficult to verify that everything on your machine is properly prepared, so it's best to download and run the installer before getting started.


In previous versions, there was also a package called NServiceBus.Interfaces. It has now been deprecated. Most users should be using unobtrusive mode conventions, which we will cover in depth in Chapter 5, Advanced Messaging. For simple exercises, wherever NServiceBus.Interfaces is used, it should be replaced by the core NServiceBus package.