Wednesday, March 16, 2016

Hello World - NServiceBus

It was sunny afternoon in October and Jimmy Bogard who is Chief Architect was right in front of us explaining  'How NServiceBus works'. 

Communication is backbone of IT industry and Service Bus is it's nerve system. Though it is relatively new, going further, Service Bus will be important factor in IT industry which will change entire communication architecture

NServicebus is a open source and can be downloaded from http://particular.net/downloads. (Detailed steps are provided below)

NServiceBus has following inbuilt capabilities -

  • Async Messaging
  • Windows Failover Cluster
  • Performance Counter
  • Detailed Performance Data 
  • Custom Checks 

What you will learn at the end of this blog -
  • How to Write Hello World NServiceBus
Prerequisite
  • NServiceBus Nuget Package 
NServiceBus Nuget Package
  1. 1. Download NServieBus open source from http://particular.net/downloads
2. You will get following screen which says

    To install NServiceBus core libraries from Nuget, open the Package Manager Console and type

              :

3. Getting Nuget Libraries in Visual Studio Project 
  • Open Visual Studio 2015
  • Click on File -> New -> Project 
  • Click on Installed -> Templates -> Windows 
  • Select Project of type Class Library 
  • Provide Name - Hello World
  • Location to store the project , In this example I have taken 'C:\Blogs\NServiceBus'
  • Keep remaining options as it is. 
                             
  • You will get following screen
                         

Now we need to add NServiceBus.Host and NServiceBus.RavenDB Nuget references in our projects

  • Right click on References ->  Manage Nuget Packages 
  • You will get following screen, follow steps mentioned in the scree for both references. 


  • You can see 'EndpointConfig.cs' is already added in the project.
  • Change original program as shown below.  
      namespace HelloWorld
      {
        using NServiceBus;
        using NServiceBus.Logging;
        using NServiceBus.Persistence;
        public class EndpointConfig : IConfigureThisEndpoint, AsA_Client,               
                                      IWantToRunWhenBusStartsAndStops
        {
           public void Customize(BusConfiguration configuration)
           {
            configuration.UsePersistence<RavenDBPersistence>();
           }
           public void Start()
           {
            LogManager.GetLogger("EndpointConfig").Info("Hello Distributed World!");
           }
           public void Stop()
           {

           }
       }
      }
  • Click on F5
  • You will see following screen 
  • You have finished your first program 'Hello World' for NServiceBus