Customizing Error Handling

Component: NServiceBus
NuGet Package NServiceBus (3.x)
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.

IManageMessageFailures allows custom actions when messages continue to fail after the Immediate Retries have been attempted.

When enabling this extension, second-level retries will not be invoked. Versions 6 and above offer better control of customization through the message pipeline.
public class CustomFaultManager :
    IManageMessageFailures
{
    public void SerializationFailedForMessage(TransportMessage message, Exception e)
    {
        // implement steps for this message when the failure is due to deserialization
    }

    public void ProcessingAlwaysFailsForMessage(TransportMessage message, Exception e)
    {
        // implement steps for this message after it fails all Immediate Retry attempts
    }

    public void Init(Address address)
    {
        // implement initializations for the custom fault manager.
    }
}

This extension needs to be registered in dependency injection so that it can be invoked when failures occur. Registration of this component can be done using the INeedInitialization interface. See also dependency-injection child lifetime.

var components = Configure.Instance.Configurer;
components.ConfigureComponent<CustomFaultManager>(DependencyLifecycle.InstancePerCall);

Related Articles


Last modified