AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/nservicebus/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Handler Ordering

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

In the past, message handlers used to be the only way to implement cross-cutting concerns like authentication, authorization, and certain kinds of validation. As those concerns needed to be applied before any other logic, it was necessary to run those handlers before all other message handlers. These message handler classes implemented IHandleMessage<IMessage> or IHandleMessage<Object> so that they would handle all incoming messages.

If it is not possible to migrate this kind of functionality out of message handlers, the order in which they will be executed can be specified.

Specifying one handler to run first

endpointConfiguration.ExecuteTheseHandlersFirst(typeof(HandlerB));

Specifying multiple handlers to run in order

endpointConfiguration.ExecuteTheseHandlersFirst(
    typeof(HandlerB),
    typeof(HandlerA),
    typeof(HandlerC));

The remaining handlers (i.e. ones not specified in the ordering) are executed in a non-deterministic order.