Customizing Error Handling

Component: NServiceBus | Nuget: NServiceBus (Version: 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.
Edit
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 the container so that it can be invoked when failures occur. Registration of this component can be done using the INeedInitialization interface. Read this article for more details on how to register custom components in the container.

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

Related Articles


Last modified