Critical Error Behavior

Component: Azure Cloud Service Host
NuGet Package NServiceBus.Hosting.Azure (8-pre)
Target NServiceBus Version: 7.x
This page targets a pre-release version and is subject to change prior to the final release.
The NServiceBus Azure Host will be deprecated as of Version 9. Refer to the upgrade guide for further details.

Handling critical errors

Versions 6.2.2 and above

The Azure host is terminated on critical errors by default. When host is terminated, the Azure Fabric controller will restart the host automatically.

Versions 6.2.1 and below

The Azure host is not terminated on critical errors by default and only shuts down the bus. This would cause the role not to process messages until the role host is restarted. To address this, probably undesired behavior, implement a critical errors action that shuts down the host process instead.

// Configuring how NServiceBus handles critical errors
    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

        var fatalMessage = $"Critical error:\n{context.Error}\nShutting down.";
        Environment.FailFast(fatalMessage, context.Exception);
        return Task.CompletedTask;

Last modified