Search code examples
nservicebus

NServiceBus - intercept application failure


I have following situation: My application which uses NServiceBus has to work with remote MSSQL Server which often not available, so application fails after some time. Is there a way to intercept that event using NServiceBus and send email (or perform any other action) before application closes?


Solution

  • NServiceBus has some options, but also some caveats

    • NServiceBus can 'catch' exceptions, retry messages and inform you about its status. But this only happens on incoming messages. In other words, no messages means no notifications.
    • You can use heartbeats and/or custom checks
    • It's up to you, but is it not an option to use proper software which is intended for monitoring things like this?

    I am assuming you're not using the remote SQL Server as a transport, because that would make things even more difficult.

    Messages get retried when something fails. NServiceBus is unaware of the severity of the error, etc. but you can work with the immediate, delayed and failed notifications. Documentation can be found here.

    You can also use heartbeats to see if an NServiceBus endpoint is still alive, or write custom checks. More info here: