SlideShare a Scribd company logo
1 of 25
Distributed Application Development with NServiceBus David Boike www.make-awesome.com @DavidBoike Presentation and source: http://bit.ly/fOn4U9
Real-Life Example using (TransactionScopets = newTransactionScope()) { InsertOrUpdateAlertPreferences(); UpdateAlertEmails(); InternalWebService.UpdateEmailSettings(listID, 		emailAddresses); ts.Complete(); }
Real-Life Example – It Gets Worse using (TransactionScopets = newTransactionScope()) { InsertOrUpdateAlertPreferences(); UpdateAlertEmails(); InternalWebService.UpdateEmailSettings(listID, 		emailAddresses); ExternalWebService.UpdateSmsSettings(keyword, phoneNumber); ts.Complete(); }
NServiceBus to the rescue! Enterprise Service Bus for .NET Not a centralized broker like BizTalk Not a services communication framework like WCF Created by UdiDahan, internationally renowned expert on software architecture and design Focuses on messaging and publish/subscribe Ultra reliable Provides friction against poor architecture decisions
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
App How an Endpoint Works MSMQ Transactional Receive
Transaction App How an Endpoint Works MSMQ Transactional Receive
Transaction How an Endpoint Works Perform database operations within the distributed transaction MSMQ DB App
Transaction How an Endpoint Works Or connect to a traditional web service MSMQ App Web Service
Transaction App How an Endpoint Works Send or publish additional messages MSMQ
Transaction Transient Errors If an exception happens, the transaction rolls back and returns the message to the queue. Transaction Rolling Back MSMQ Automatic retries are an integral part of the system. Exception App
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
Real-Life Example - Revisited Webapp Bus.Send(new SaveAlertsCmd()); Alert Service Bus.Publish(new AlertsUpdatedEvent()); Subscriptions Bus.Subscribe<AlertsUpdatedEvent>(); Web Svc Adapter SMS Adapter
Getting Started Go to http://www.nservicebus.com Click the Download link Follow the instructions Be sure to run RunMeFirst.bat fromthe 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.
Let’s Build Something
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.
Code Phase 1: Messaging Create MyMessages assembly Add reference to NServiceBus.dll Add CreateUserCmd
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
Code Phase 1: Messaging 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
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
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
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)
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
All caught up!
Where to learn more NServiceBus website: www.nservicebus.com My  blog: www.make-awesome.com Ask on Stack Overflow (tag with “nservicebus”) Udi’sblog: www.udidahan.com Andreas Ohlund’sblog: www.andreasohlund.net Jonathan Oliver’s blog: www.jonathanoliver.com Twitter: #NServiceBus Presentation Source Code: http://bit.ly/fOn4U9

More Related Content

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Distributed Application Development with NServiceBus

  • 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 by 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 and returns 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 fromthe 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.
  • 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. Code Phase 1: Messaging 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
  • 25. Where to learn more NServiceBus website: www.nservicebus.com My blog: www.make-awesome.com Ask on Stack Overflow (tag with “nservicebus”) Udi’sblog: www.udidahan.com Andreas Ohlund’sblog: www.andreasohlund.net Jonathan Oliver’s blog: www.jonathanoliver.com Twitter: #NServiceBus Presentation Source Code: http://bit.ly/fOn4U9