Learning NServiceBus - Second Edition
By David Boike
()
About this ebook
- Harness the power of Publish/Subscribe to build robust applications
- Build reliable message-driven systems that automatically compensate for system failure
- A concise and example-oriented guide to building reliable and scalable systems with SOA principles
If you are a .NET developer who wants to eliminate the problems related to defective third-party web service integration or batch job failures, then this is the book for you. It is also perfect for those of you who are new to NServiceBus and service-oriented architecture and would like to learn how you can streamline all of your development efforts.
David Boike
David Boike is a Principal Consultant with ILM Professional Services with more than a decade of development experience in ASP.NET and related technologies and has been an avid proponent of NServiceBus since Version 2.0 in 2010. He is also an alumnus of Udi Dahan's Advanced Distributed Systems Design course. David resides in the Twin Cities with his wife and daughter. He can be found on Twitter at @DavidBoike and on his blog at http://www.make-awesome.com.
Related to Learning NServiceBus - Second Edition
Related ebooks
Learning NServiceBus Sagas Rating: 0 out of 5 stars0 ratingsPractical PowerShell Exchange Online Rating: 0 out of 5 stars0 ratingsBreaking the Availability Barrier Ii: Achieving Century Uptimes with Active/Active Systems Rating: 0 out of 5 stars0 ratingsExecutive's Guide to Solvency II Rating: 0 out of 5 stars0 ratingsLearning Microsoft Cognitive Services Rating: 0 out of 5 stars0 ratingsHands-on Ansible Automation: Streamline your workflow and simplify your tasks with Ansible (English Edition) Rating: 0 out of 5 stars0 ratingsEffective Vulnerability Management: Managing Risk in the Vulnerable Digital Ecosystem Rating: 0 out of 5 stars0 ratingsXBRL Standard Requirements Rating: 0 out of 5 stars0 ratingsIf It's Smart, It's Vulnerable Rating: 4 out of 5 stars4/5Application Architecture Standard Requirements Rating: 0 out of 5 stars0 ratingsInternational business development Third Edition Rating: 0 out of 5 stars0 ratingsMastering Go Network Automation: Automating Networks, Container Orchestration, Kubernetes with Puppet, Vegeta and Apache JMeter Rating: 0 out of 5 stars0 ratingsThink Blockchain: A Student's Guide to Blockchain's Evolution from Bitcoin, Ethereum, Hyperledger to Web3. Rating: 0 out of 5 stars0 ratingsThe Network Security Test Lab: A Step-by-Step Guide Rating: 0 out of 5 stars0 ratingsVMware NSX A Complete Guide - 2020 Edition Rating: 0 out of 5 stars0 ratingsIBM Rational Team Concert 2 Essentials Rating: 0 out of 5 stars0 ratingsPractical OneOps Rating: 0 out of 5 stars0 ratingsBuilding a RESTful Web Service with Spring Rating: 5 out of 5 stars5/5Instant RESS Implementation: How To Rating: 0 out of 5 stars0 ratingsAuthor Experience Rating: 0 out of 5 stars0 ratingsRESTful Web API Design with Node.js - Second Edition Rating: 1 out of 5 stars1/5RabbitMQ Essentials Rating: 0 out of 5 stars0 ratingsComputer Programming: From Beginner to Badass—JavaScript, HTML, CSS, & SQL Rating: 3 out of 5 stars3/5Mastering NServiceBus and Persistence Rating: 0 out of 5 stars0 ratingsNagios 3 Enterprise Network Monitoring: Including Plug-Ins and Hardware Devices Rating: 0 out of 5 stars0 ratingsNW.js Essentials Rating: 0 out of 5 stars0 ratingsMQTT Essentials - A Lightweight IoT Protocol Rating: 0 out of 5 stars0 ratingsInstant Nancy Web Development Rating: 0 out of 5 stars0 ratingsPHPEclipse: A User Guide Rating: 3 out of 5 stars3/5Implementing OpenShift Rating: 0 out of 5 stars0 ratings
Internet & Web For You
No Place to Hide: Edward Snowden, the NSA, and the U.S. Surveillance State Rating: 4 out of 5 stars4/5How to Be Invisible: Protect Your Home, Your Children, Your Assets, and Your Life Rating: 4 out of 5 stars4/5Social Engineering: The Science of Human Hacking Rating: 3 out of 5 stars3/5The Gothic Novel Collection Rating: 5 out of 5 stars5/5Get Rich or Lie Trying: Ambition and Deceit in the New Influencer Economy Rating: 0 out of 5 stars0 ratingsSix Figure Blogging Blueprint Rating: 5 out of 5 stars5/5Coding For Dummies Rating: 5 out of 5 stars5/5How to Disappear and Live Off the Grid: A CIA Insider's Guide Rating: 0 out of 5 stars0 ratingsEverybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Podcasting For Dummies Rating: 4 out of 5 stars4/5The Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5Beginner's Guide To Starting An Etsy Print-On-Demand Shop Rating: 0 out of 5 stars0 ratingsGrokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5The Beginner's Affiliate Marketing Blueprint Rating: 4 out of 5 stars4/5200+ Ways to Protect Your Privacy: Simple Ways to Prevent Hacks and Protect Your Privacy--On and Offline Rating: 0 out of 5 stars0 ratingsHacking : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Ethical Hacking Rating: 5 out of 5 stars5/5The Internet Is Not What You Think It Is: A History, a Philosophy, a Warning Rating: 4 out of 5 stars4/5The Logo Brainstorm Book: A Comprehensive Guide for Exploring Design Directions Rating: 4 out of 5 stars4/5Remote/WebCam Notarization : Basic Understanding Rating: 3 out of 5 stars3/5How To Start A Podcast Rating: 4 out of 5 stars4/5Tor and the Dark Art of Anonymity Rating: 5 out of 5 stars5/5More Porn - Faster!: 50 Tips & Tools for Faster and More Efficient Porn Browsing Rating: 3 out of 5 stars3/5The Digital Marketing Handbook: A Step-By-Step Guide to Creating Websites That Sell Rating: 5 out of 5 stars5/5The Cyber Attack Survival Manual: Tools for Surviving Everything from Identity Theft to the Digital Apocalypse Rating: 0 out of 5 stars0 ratingsIntroduction to Internet Scams and Fraud: Credit Card Theft, Work-At-Home Scams and Lottery Scams Rating: 4 out of 5 stars4/5
Reviews for Learning NServiceBus - Second Edition
0 ratings0 reviews
Book preview
Learning NServiceBus - Second Edition - David Boike
Table of Contents
Learning NServiceBus Second Edition
Credits
Foreword
Early influences
Starting with MSMQ
What open source meant in those days
Clouds on the horizon
Unexpected success
Fast-forward to today
Back to David, and this book
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Instant updates on new Packt books
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting on the IBus
Why use NServiceBus?
Getting the code
NServiceBus NuGet packages
Our first example
Creating a message assembly
Creating a service endpoint
Creating a message handler
Sending a message from an MVC application
Creating the MVC website
Running the solution
Summary
2. Messaging Patterns
Commands versus events
Eventual consistency
Achieving consistency with messaging
Events
Publishing an event
Subscribing to an event
Message routing
Summary
3. Preparing for Failure
Fault tolerance and transactional processing
Error queues and replay
Automatic retries
Replaying errors
Second-level retries
RetryDemo
Messages that expire
Auditing messages
Web service integration and idempotence
Summary
4. Hosting
Hosting types
NServiceBus-hosted endpoints
Self-hosted endpoints
Assembly scanning
Choosing an endpoint name
Dependency injection
Message transport
Reasons to use a different transport
MSMQ
RabbitMQ
SQL Server
Windows Azure
Persistence
In-memory persistence
NHibernate
RavenDB
Windows Azure
Polyglot persistence
Message serialization
Transactions
Purging the queue on startup
Installers
Startup
Send-only endpoints
Summary
5. Advanced Messaging
Unobtrusive mode
TimeToBeReceived attribute
Message versioning
Polymorphic dispatch
Events as interfaces
Specifying the handler order
Message actions
Stopping a message
Deferring a message
Forwarding messages
Message headers
Property encryption
Transporting large payloads
Exposing web services
Summary
6. Sagas
Long-running processes
Defining a saga
Finding saga data
Ending a saga
Dealing with time
Design guidelines
Business logic only
Saga lifetime
Saga patterns
Messages that start sagas
Retraining business stakeholders
Persistence concerns
RavenDB
NHibernate
Azure
Unit testing
Testing events as interfaces
Scheduling
Summary
7. Advanced Configuration
Extending NServiceBus
IConfigureThisEndpoint
INeedInitialization
IWantToRunWhenBusStartsAndStops
Dependency injection
Unit of work
Message mutators
The NServiceBus pipeline
Building behaviors
Ordering behaviors
Replacing behaviors
The pipeline context
Outbox
DTC 101
Life without distributed transactions
Outbox configuration
Session sharing
Summary
8. The Service Platform
ServiceControl
ServiceInsight
Endpoint Explorer
Messages
Main view
Flow Diagram
Saga
Sequence Diagram
Other tabs
ServicePulse
Endpoint activity
Failed messages
Custom checks
Getting notified
ServiceMatrix
Summary
9. Administration
Service installation
Infrastructure installers
Side-by-side installation
Profiles
Environmental profiles
Feature profiles
Customizing profiles
Logging profiles
Customizing the log level
Managing configurations
Monitoring performance
Scalability
Scaling up
Scaling out
Decommissioning a MSMQ worker
Extreme scale
Multiple sites
Virtualization
MSMQ message storage
Clustering
Transport administration
Summary
10. Where to Go from Here?
What we've learned
What next?
Index
Learning NServiceBus Second Edition
Learning NServiceBus Second Edition
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: August 2013
Second edition: January 2015
Production reference: 1250115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-292-5
www.packtpub.com
Credits
Author
David Boike
Reviewers
Prashant Brall
Roy Cornelissen
Hadi Eskandari
Daniel Marbach
Commissioning Editor
Dipika Gaonkar
Acquisition Editor
Larissa Pinto
Content Development Editor
Kirti Patil
Technical Editor
Chinmay S. Puranik
Copy Editors
Dipti Kapadia
Vikrant Phadke
Project Coordinator
Kranti Berde
Proofreaders
Simran Bhogal
Maria Gould
Ameesha Green
Bernadette Watkins
Indexer
Monica Ajmera Mehta
Graphics
Sheetal Aute
Abhinash Sahu
Production Coordinators
Arvindkumar Gupta
Nilesh R. Mohite
Cover Work
Arvindkumar Gupta
Nilesh R. Mohite
Foreword
Unlike many people who write a foreword for a book, I have myself not actually written a book yet, so I am probably going about this the wrong way. Also, of all the books that I have read, I have almost never read the foreword, which makes me wonder who is actually reading this.
That being said, I think that 10 years of blogging has actually prepared me very well to write this foreword, and it will end up being roughly as long as my regular blog posts.
In any case, I am extremely happy to see how well the first edition of this Learning NServiceBus book has done, and when David asked me to write the foreword for this second edition, I was more than willing to oblige.
Now that you've picked up this book, I think it's fair to assume that you have heard something about NServiceBus, maybe even downloaded it, played with it, or used it on a project or two. What you might not know is the story of how it all began and how we ended up where we are today—seeing the second edition of Learning NServiceBus being published.
Early influences
Almost 15 years ago, I was working as a developer on a gigantic command and control system developed in a language called Ada. This is what Wikipedia has to say about Ada:
[Ada] has built-in language support for explicit concurrency, offering tasks, synchronous message passing, protected objects, and non-determinism.
These were very important attributes for a system that needed to be super reliable, highly performant, and very scalable. Little did I realize at that time how profound an effect this relatively unknown programming language would have on the rest of my career.
In my next company, a software development firm—the kind that does turnkey projects for its customers—I continued my focus on command and control systems, this time using the fairly new .NET platform from Microsoft. The thing was that many of the abilities that I'd come to rely on in Ada were (to me) curiously absent from .NET.
Like any good craftsman who has gotten used to a certain tool, I started looking around for a replacement, and when I couldn't find one, I went and made it myself.
Starting with MSMQ
Although the main message from Microsoft at the time was all about XML Web Services and .NET Remoting, I found that there was support for a message passing model in .NET that was actually built on a piece of infrastructure that was considerably older (originally built in the NT 3.5.1 days, but released with NT 4.0 in 1997). At that time, MSMQ had made it to version 3.0 which, later on, I learned was the magic number when it came to stability of software built by Microsoft.
Still, I found the System Messaging API to be a little too close to the metal for me to feel comfortable using it directly from my application logic, so I created a wrapper library, which gave me some much needed abstraction.
As I moved from one project to the next, I found this little library to be more and more useful and kept on extending and refining it. The developers in my teams seemed to like working with it as well.
After the third or fourth project, I decided to approach the company's management, suggesting that we should consider turning this infrastructure into a product. Seeing how useful it was to us on our projects, I figured that it was a no-brainer.
It turned out that this company had gone down the productization path in the past and had gotten badly burned in the process. As a result, they were very hesitant to make the same mistake again. Realizing that it wasn't going to happen, I managed to get permission to release the infrastructure to the world as an open source project, but only after legal confirmation that there would be no support or other liabilities to the company.
Thus, in 2007, NServiceBus was born.
This also happened to be the time when I started transitioning into my own private consulting practice.
What open source meant in those days
As I continued to use NServiceBus in my work projects, I kept tweaking and expanding it. Version numbers didn't mean a whole lot, and through 2008, the version progressed rapidly from 1.6.1 to a release candidate of 1.9. If it worked on my project, I considered it worthy to ship.
Documentation was practically nonexistent and developers leaned pretty heavily on samples to figure out what the software did, asking questions on the discussion group when they ran into cryptic error messages (of which there were many).
In 2008, the 5-day format of my Advanced Distributed Systems Design course was launched, which was an extension of the 2-day workshop on the same topics I had been teaching since 2006. This course was based on many of the learnings from my old Ada days and continues to serve as the architectural underpinning of much of NServiceBus to this day.
April 2009 brought some stability with the final release of version 1.9 but came with a marked increase in the amount of consulting and training I was doing. This was great for me as I could finally afford to turn down work in order to continue the development of NServiceBus. This worked out great and in March 2010, the much-heralded NServiceBus 2.0 was finally released.
Clouds on the horizon
By almost every measure, things were going great. More companies were adopting NServiceBus and bringing me in for consulting. The Advanced Distributed Systems Design course was getting quite popular, and for a while, I was teaching it almost once a month in a different country around the world. Unfortunately, almost 6 months had gone by without any meaningful development on the code base.
Then it hit me that if another year or two would pass by in this manner, NServiceBus would start to get stale and the companies that had used it in their systems would eventually have to replace it with something else (costing them quite a lot of time and money).
I had lived through this story several times as a consumer of open source projects. As long as the project wasn't too intertwined in our system, it wasn't too painful to remove it. The thing was that NServiceBus was a fairly large framework that supported broad cross-sections of both client-side and server-side logic, so there would be no simple way to replace it.
I tried to figure out how I could guarantee that the development of the code base would stay a priority, yet as long as my primary source of revenue was services (consulting and training), I couldn't see how it would work. The only solution seemed to be to start charging money for NServiceBus licenses. Although larger companies were able to keep an open source core and sell other products around it, I hadn't seen or heard of any one-person operations that had been able to bootstrap their way into that.
I had no idea whether this would work, and whether the open source community that had supported me all this time would accept it or turn their backs on me, but I felt that it needed to be done. Unless there was revenue coming in directly from the features of the product, it wouldn't have a future.
Therefore, in late 2010, I founded the NServiceBus company and steeled myself for the worst.
Unexpected success
Seeing the overwhelmingly positive responses from the community was quite a surprise. Sure, there were those that grumbled, but only a handful ultimately decided to switch to something else.
I had made it—living the dream!
However, lest I paint an overly rosy picture, I knew nothing about running a product company. Pricing was harder than I ever imagined it would be. The legal factor was a crazy-complex
where, even after the lawyers explained to me all about things such as indemnification, they told me that it was ultimately my decision whether to accept the client's terms or not.
Most importantly though, I felt that I had secured the future of NServiceBus. As long as there was money to be made from it, even if something happened to me, one of the other contributors to the project could afford to take it over.
Fast-forward to today
So much has happened since those early days of 2011 that it could probably fill its own book, and maybe one of these days, I'll put the proverbial pen to paper and make it happen. Anyway, here are the highlights:
March 2012: NServiceBus 3.0 released. This includes official Azure support for the first time.
July 2013: NServiceBus 4.0 released. This includes modeling and debugging tools.
2013: The company begins to rebrand itself as Particular Software.
August 2013: The first edition of the Learning NServiceBus book comes out.
November 2013: Monitoring tools released for NServiceBus.
April 2014: The first release of the integrated Particular Service Platform.
September 2014: NServiceBus 5.0 released, no longer depending on distributed transactions.
Also, I've got to tell you, the quality of each version has gone up dramatically over time. The level of testing that goes into each release is impressive—looping through every permutation of containers, persistence, transport, and even versions of supported operating systems and databases.
Back to David, and this book
When David wrote the first edition of this Learning NServiceBus book, it was something of a defining moment for NServiceBus—there was finally a book. The technology industry is awash in books about almost every piece of software out there, but for most of the time, NServiceBus was absent. Decision makers took us more seriously when we'd bring physical books with us for their teams.
Books matter!
With this latest edition, David goes beyond just covering the changes that happened in NServiceBus version 5.0, and goes even deeper into the reasoning behind those changes and why you'd want to use which features and when.
As one of the most prominent members of the NServiceBus community, David has interacted with the NServiceBus development team on a regular basis, given valuable feedback on our API, and debated with us on our future technology roadmap.
You're in for a treat.
Udi Dahan
Founder and CEO, Particular Software
About the Author
David Boike is a principal consultant with ILM Professional Services, with experience in building and teaching others how to build distributed systems. He is an NServiceBus Champion, official NServiceBus and RavenDB trainer, Xamarin Certified developer, and amateur beer brewer. He lives in the Twin Cities with his wife and two children.
About the Reviewers
Prashant Brall is a principal consultant and senior software architect and developer at Veritec (www.veritec.com.au) in Canberra, Australia. He has over 19 years of experience in application development, which includes 4 years of work in the USA for Fortune 500 companies and major financial corporations. As a software professional, Prashant loves crafting software and enjoys writing about his experiences on his blog at https://prashantbrall.wordpress.com. He has also reviewed Instant AutoMapper published by Packt Publishing.
In his leisure time, he enjoys watching movies with his wife and playing musical instruments such as piano and guitar.
A big thank you to my wife, Jhumur, for her love and support and for being my best friend. I would also like to thank my parents, Mr. Hem Brall and Mrs. Prabha Brall, for encouraging me and showing me the difference between right and wrong throughout my childhood.
Hadi Eskandari, while working on both Java and .NET technologies, has developed enterprise-level applications on both platforms. He is a regular contributor to various open source projects. Currently, he is working as a senior software developer at Readify, which is a leading company on .NET technology in Australia.
I'd like to thank my family for their support. This wouldn't have been possible without your encouragement and help.
Roy Cornelissen works as a software architect in the Netherlands. With over 15 years of experience in IT, he has designed and built many enterprise systems for customers using Microsoft, Particular, and Xamarin technologies.
As a lead consultant at Xpirit, Roy is responsible for the vision and strategy for the Enterprise Mobile Development competence. He specializes in designing and building mobile applications for iOS,