Distributed Application Development with NServiceBus
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Distributed Application Development with NServiceBus

on

  • 3,341 views

Building reliable, scalable, maintainable distributed applications is next to impossible without the right tools. NServiceBus is an open-source .NET framework that will help you to do just that.

Building reliable, scalable, maintainable distributed applications is next to impossible without the right tools. NServiceBus is an open-source .NET framework that will help you to do just that.

This code-focused presentation covers the fundamentals of NServiceBus development, including one-way messaging, publish and subscribe, and implementing long-running business processes.

In the code example, we start with fairly simple code for a user to create an account on a website and expand it to include an email verification feature using NServiceBus.

In the first phase, we’ll move the work of creating the user into the service layer, so that we can get an example of how NServiceBus works at its most fundamental level.

In the second phase, we will up the ante significantly, using a Saga (a long running business process) to implement an email verification check. This includes sending an email with a verification code to the user, and then verifying that code before finally creating the user.

Statistics

Views

Total Views
3,341
Views on SlideShare
2,869
Embed Views
472

Actions

Likes
1
Downloads
62
Comments
0

3 Embeds 472

http://www.make-awesome.com 452
https://jabbr.net 19
http://translate.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Distributed Application Development with NServiceBus Presentation Transcript

  • 1. Distributed Application Development with NServiceBus
    David Boike
    www.make-awesome.com
    @DavidBoike
    Presentation and source: http://bit.ly/fOn4U9
  • 2. Real Life Example
    using (TransactionScopets = newTransactionScope())
    {
    InsertOrUpdateAlertPreferences();
    UpdateAlertEmails();
    InternalWebService.UpdateEmailSettings(listID, emailAddresses);
    ts.Complete();
    }
  • 3. Real Life Example – It Gets Worse
    using (TransactionScopets = newTransactionScope())
    {
    InsertOrUpdateAlertPreferences();
    UpdateAlertEmails();
    InternalWebService.UpdateEmailSettings(listID, emailAddresses);
    ExternalWebService.UpdateSmsSettings(keyword, phoneNumber);
    ts.Complete();
    }
  • 4. NServiceBus to the rescue!
    Enterprise Service Bus for .NET
    Not a centralized broker like BizTalk
    Not a services communication framework like WCF
    Created UdiDahan, internationally renowned expert on software architecture and design
    Focuses on messaging and publish/subscribe
    Ultra reliable
    Provides friction against poor architecture decisions
  • 5. How it Works
    Utilizes assembly scanning for component discovery
    Uses marker interfaces to identify message schemas, message handlers, configuration sources, etc.
    Uses dependency injection (inversion of control) to detect and provide dependencies and services
    Everything is pluggable
  • 6. App
    How an Endpoint Works
    MSMQ
    Transactional
    Receive
  • 7. Transaction
    App
    How an Endpoint Works
    MSMQ
    Transactional
    Receive
  • 8. Transaction
    How an Endpoint Works
    Perform database operations within the distributed transaction
    MSMQ
    DB
    App
  • 9. Transaction
    How an Endpoint Works
    Or connect to a traditional web service
    MSMQ
    App
    Web Service
  • 10. Transaction
    App
    How an Endpoint Works
    Send or publish additional messages
    MSMQ
  • 11. Transaction
    Transient Errors
    If an exception happens, the transaction rolls back, returning the message to the queue.
    Transaction
    Rolling Back
    MSMQ
    Automatic retries are an integral part of the system.
    Exception
    App
  • 12. Poison Messages
    After a configurable number of retries, poison messages get sent to an error queue.
    Transaction
    Rolling Back
    MSMQ
    Fix the underlying issue, and you can return error messages to their source queue.
    App
    Error
  • 13. Real Life Example - Revisited
    Webapp
    Bus.Send(new SaveAlertsCmd());
    Alert
    Service
    Bus.Publish(new AlertsUpdatedEvent());
    Subscriptions
    Bus.Subscribe<AlertsUpdatedEvent>();
    Web Svc Adapter
    SMS Adapter
  • 14. Getting Started
    Go to http://www.nservicebus.com
    Click the Download link
    Follow the instructions
    Be sure to run RunMeFirst.bat via the command prompt with admin rights!
    Installs and/or verifies MSMQ configuration
    Sets the appropriate settings on the Microsoft Distributed Transaction Coordinator
    Installs performance counters
    Run from the command prompt so you can see if there are any errors.
  • 15. Let’s Build Something
  • 16. In case you missed it…
    If you are watching the presentation live, the next several slides are apt to be very boring.
    Sorry.
    For those of you at home, this is what we did so you can follow along in the code samples.
  • 17. Code Phase 1: Messaging
    Create MyMessages assembly
    Add reference to NServiceBus.dll
    Add CreateUserCmd
  • 18. Code Phase 1: Messaging
    Create UserService assembly
    Add reference to NServiceBus.dll, NServiceBus.Core.dll, NServiceBus.Host.exe, and Log4Net
    Add IConfigureThisEndpoint, AsA_Publisher
    Add UserCreatorservice implementing IHandleMessages<CreateUserCmd>
    Add Start Action to run NServiceBus.Host.exe
  • 19. Modify web project
    Add Global.asax, providing a global home for the web application’s IBus instance
    Modify Web.config with NServiceBus configuration
    Modify Register.aspx.cs to send the message
  • 20. Code phase 2: Saga/Verification
    CreateUserSagaData : ISagaEntity
    Copy properties from CreateUserCmd
    Add VerificationString property
    Change from service handling CreateUserCmd to saga started by CreateUserCmd
    Set saga data from command
    Override ConfigureHowToFindSaga, calling ConfigureMapping<CreateUserCmd>() method
  • 21. Code phase 2: Saga/Verification
    “Send” verification email
    Create SendVerificationEmailCmd
    Create mock handler that logs verification code to console
    Configure UserCreatorApp.config to send to the UserService (itself, although this could be a separate project)
    Send SendVerificationEmailCmd from the Handle<CreateUserCmd> method
  • 22. Code phase 2: Saga/Verification
    Verify the Email
    Create VerifyEmailCmd in MyMessages
    Create UserCreatedEvent in MyMessages
    Add IHandle<VerifyEmailCmd> to saga and configure how to find saga data from this command
    Add implementation, actually creating user in DB
    MarkAsComplete(), log, and Bus.Return(0)
  • 23. Code phase 2: Saga/Verification
    Web Handler for email link
    Create Verify.aspx
    Configure Web.config to send VerifyEmailCmd to UserService
    Change Register.aspx.cs redirect from Login to Verify
  • 24. All caught up!
  • 25. Where to learn more
    NServiceBus Website: www.nservicebus.com
    My Blog: www.make-awesome.com/tags/nservicebus
    Ask on Stack Overflow (tag with “nservicebus”)
    Udi’s Blog: www.udidahan.com
    Andreas Ohlund’s Blog: www.andreasohlund.net
    Jonathan Oliver’s Blog: www.jonathanoliver.com
    Twitter: #NServiceBus