Cancellation in NServiceBus 8

NServiceBus endpoints have always been good at running reliably, but they could have been better at stopping. And when you want an endpoint to stop, you want it to stop…now.
In NServiceBus 8.0, which is now available, we have introduced support for cooperative cancellation, which will give you greater control over how an NServiceBus endpoint behaves when you need to shut it down.
Let’s talk about what cancellation is, how it relates to NServiceBus, and how we’re delivering cancellation in NServiceBus 8 without forcing a massive breaking change on your existing systems.
Read moreIf you remember the upgrade to NServiceBus 6, we had a similar interface change to support async/await. While we still stand by that change now, it's not something we care to repeat.
This technically means anywhere one of your method parameters implements
ICancellableContext
. This is a new interface we added as it includes bothIPipelineContext
(from whichIMessageHandlerContext
derives) as well asIBehaviorContext
....or behaviors. But message handlers are far more common, so we'll focus on them here.
NServiceBus already has an analyzer that makes sure you don't forget to
await
aTask
returned by one of our APIs, and a suite of saga analyzers to make saga development easier.Come on, admit it, you do. I do too. Let's just all agree most of those messages aren't worth our time, right?
silent
andnone
may sound like the same thing, but they're not. If you choosesilent
, you don't get any squigglies or dots in the code, but if you hover your mouse over the code, you'll still get the analyzer message. If you choosenone
, then the analyzer won't report diagnostics at all.