Aborting Pipeline execution

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

From inside a Handler

From the context of a Handler further Handler execution can be aborted by calling the DoNotContinueDispatchingCurrentMessageToHandlers() method. This method instruct the bus not to pass the current message on to subsequent handlers in the pipeline. This is often used by authentication and authorization handlers when those checks fail.

class Handler :
    IHandleMessages<MyMessage>
{
    IBus bus;

    public Handler(IBus bus)
    {
        this.bus = bus;
    }

    public void Handle(MyMessage message)
    {
        // may want to log a reason here
        bus.DoNotContinueDispatchingCurrentMessageToHandlers();
    }
}

Aborting the pipeline does not fail the message processing. The message that was processed will be marked as successfully completed.

Handler execution order by default is non-deterministic. To configure the ordering see Handler Ordering.

Last modified