Archives

  • Categories

  • Getting Started With NServiceBus: Part 1 Unicast Messaging

    I’ve been doing a bit of work with NServiceBus recently on a project and found it to be a really powerful and robust tool once you get it working. However like most open source projects and Udi will admit this himself the documentation is somewhat lacking.

    I haven’t done anything too complicated with NServiceBus and these are more notes for myself rather than anything else but I thought i’d put up a series of posts on some of the basic scenarios.

    Part 1 Unicast Messaging.
    Part 2 Publishing and Subscribing.
    Part 3 Sagas
    Part 4 Integrating With StructureMap

    Configuring The Client

    This is your basic point to point messaging and is very similar to your typical wcf client calling a wcf service. This example show how to get NServiceBus working in your own application rather than using the self host.

    1) Reference NServiceBus.dll & NServiceBus.Core.dll
    2) In your Bootstrapper you need to configure NServiceBus

     Configure.With()
                    .SpringBuilder()
                    .XmlSerializer()
                    .MsmqTransport()
                    .IsTransactional(true)
                    .PurgeOnStartup(false)
                    .UnicastBus()
                    .ImpersonateSender(false)
                    .CreateBus()
                    .Start();
    

    3) In the Application Config add the following

    
    

    4) Now define the Client’s Input Queue (where response messages are sent to) and the Error Queue – where undelivered messages are put if there is an exception delivering the message in the config file

    
    

    5) Now define the endpoint you wish to send the messages to this is essentially a mapping between a message type and an endpoint queue. You can either send all messages from an assembly to a particular
    endpoint queue or you can specify a specific type. In the example below I have specified that every message in the Messages.dll should be sent to the Server_Input queue.

    
        
          
        
      
    

    Configuring The Server

    6) Repeat steps 1) & 3) for the Server
    7) Configure NServiceBus to run as a server the important difference between this and the client is the
    LoadMessageHandlers() line which means we will handle the incoming messages.

    
         Configure
                    .With()
                    .SpringBuilder()
                    .XmlSerializer()
                    .MsmqTransport()
                    .IsTransactional(true)
                    .PurgeOnStartup(false)
                    .UnicastBus()
                    .ImpersonateSender(false)
                    .LoadMessageHandlers()
                    .CreateBus()
                    .Start();
    

    8 ) Now define the Server’s Input Queue (where request messages are sent to) and the Error Queue – where undelivered messages are put if there is an exception delivering the message in the config file

    
    

    9) That’s it! when you run up the applications NServiceBus will create all the queues automatically for you (you can specify it not to do this if you wish)

    4 Responses to “Getting Started With NServiceBus: Part 1 Unicast Messaging”


    1. [...] Part 1 Unicast Messaging. Part 2 Publishing and Subscribing. [...]

    2. [...] Part 1 Unicast Messaging. Part 2 Publishing and Subscribing. [...]

    3. [...] Part 1 Unicast Messaging. Part 2 Publishing and Subscribing. Part 3 Sagas Part 4 Integrating With StructureMap [...]

    4. [...] This post was mentioned on Twitter by NeilRobbins, Mike Chaliy. Mike Chaliy said: Getting Started With NServiceBus serias http://icio.us/uej2m5 [...]

    Leave a Reply