Building with Azure Service Bus?... Take a Test Drive with the NServiceBus Sample Project

There’s been a lot of mention lately about architecting solutions using Azure Service Bus and other equivalent technologies like RabbitMQ and MSMQ.

It’s easy to see clear benefits and use cases for asynchronous messaging using both queues and topics/subscriptions. But… where do you start? It’d be nice to have a good sample application to see how this type of project is structured that isn’t just two consoles talking to each other.


NServiceBus is an abstraction over asynchronous messaging technologies like those mentioned above. Created by Udi Dahan, founder of Particular Software, it “is a messaging and workflow framework th at helps you create distributed systems that are scalable, reliable, and easy to modify.”

You can read more about NServiceBus on Particular’s website, it has excellent documentation and hands-on labs that can get you up to speed quickly.

It is a paid product, but the tooling and support offered by Particular makes it well worth the cost. Worth even more - the reduction in down time and reactivity when you implement asynchronous messaging.

Sample Project: NServiceBus over Azure Service Bus

So back to our pain of not being able to find a larger, real-world sample project that uses messaging and/or service bus…

Particular/NServiceBus has just what we’re looking for. Jump over to Particular’s Github repositories here. You’ll find all of the NServiceBus supported transports, tooling, and some of their training materials - like the HandsOnLabs and NServiceBus.Azure.Samples.

Let’s go ahead and set up an Azure Service Bus namespace:

We also need to download the Particular Service Platform Installer here. You’ll want to go ahead and install the whole platform (I’ll be following up with more on these later).

Next, we’ll clone the NServiceBus.Azure.Samples Github repository:

git clone

We want to open up the VideoStore.AzureServiceBus.OnPremises project. This represents a scenario where the application is hosted on-premise while using Azure Service Bus as a transport for NServiceBus.

The first thing we want to do is replace all of the Azure Service Bus connection strings throughout the project, as described in the README.

The easiest way to do this is a Find and Replace on the Solution for two strings:


Endpoint=sb://[your namespace];SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=[your secret]

You want to Find and Replace these with the connection string you get when you click “CONNECTION INFORMATION” for your newly created service bus namespace in Azure:

When I cloned the project, the VideoStore.Messages was set as the startup project for the solution. This project contains only the POCOs that represent the message types that are sent to the different endpoints - we need to change the startup project to VideoStore.ECommerce. This project is an MVC project that is the UI for the Video Store.

Let’s Debug…

If everything is set up correctly, when you hit F5 to debug the solution, you’ll see a new set of queues and topics in your Azure Service Bus namespace:

Locally, you should see the VideoStore.ECommerce UI:

To wrap this up and make the entire application work, we need to do one more thing, start new instances of all of our endpoints (*that’s Right Click > Debug > “Start New Instance” for each Project except VideoStore.Messages*)

You should have 4 console windows open now:

These additional endpoints also created their own queues and topics in Azure Service Bus:

When you place a successful order in the Video Store UI, you will see the order enter the Pending status, followed by 20 second “Cool Down” (allowing the customer to cancel the order), and then enter the “Orders Received” list:

Meanwhile, behind the scenes - you will see the messages move throughout your NServiceBus endpoints:


As you can see, this is an excellent starter project to learn more about how a solution is architected using NServiceBus over Azure Service Bus.

Unlike with RabbitMQ or MSMQ, Azure Service Bus has allowed us to delegate the overhead of setting up the infrastructure, while NServiceBus has given us an excellent abstraction over the service bus architecture.

So… clone the project, spin it up, sign up for my newsletter and stay tuned for more about tooling, deployment, and maintenance of message-based architectures.

comments powered by Disqus