The NServiceBus Azure Host package is deprecated as of Version 9 as Microft has deprecated the Cloud Service hosting model. Users are recommended to switch to a different cloud hosting model.
Handling critical errors
Versions 6.2.2 and above
By default, the Azure host is terminated when critical errors occur. The Azure Fabric controller restarts the host automatically.
Versions 6.2.1 and below
By default, the Azure host is not terminated when critical errors occur. Only the bus is shut down. The role does not process messages until the role host is restarted. This (probably undesired) behavior may be corrected by implementing a critical errors action that shuts down the host.
// Configuring how NServiceBus handles critical errors
endpointConfiguration.DefineCriticalErrorAction(
onCriticalError: context =>
{
var output = $"Critical exception: '{context.Error}'";
log.Error(output, context.Exception);
if (Environment.UserInteractive)
{
// so that user can see on their screen the problem
Thread.Sleep(10000);
}
var fatalMessage = $"Critical error:\n{context.Error}\nShutting down.";
Environment.FailFast(fatalMessage, context.Exception);
return Task.CompletedTask;
});