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.

Header API changes in NServiceBus Version 6

Component: NServiceBus

This is part of the NServiceBus Upgrade Guide from Version 5 to 6, which also includes the following individual upgrade guides for specific components:

Feature Details
Transports
Persistence
Hosting
Other

Setting headers on outgoing messages

Headers are now set using the new Send/Reply or Publish options. Bus.SetMessageHeader is no longer available.

See also: Header Manipulation.

Setting outgoing headers for the entire endpoint

NServiceBus allows setting headers that are applied to all outgoing messages for the entire endpoint. In version 6, this can be done using:

endpointConfiguration.AddHeaderToAllOutgoingMessages("MyGlobalHeader", "some static value");

Setting headers on the outgoing pipeline

Headers for outgoing messages can now be set using context.Headers on pipelines such as:

// For NServiceBus version 6.x
public class OutgoingBehavior :
    Behavior<IOutgoingLogicalMessageContext>
{
    public override Task Invoke(IOutgoingLogicalMessageContext context, Func<Task> next)
    {
        var headers = context.Headers;
        headers["MyCustomHeader"] = "My custom value";
        return next();
    }
}

// For NServiceBus version 5.x
public class OutgoingBehavior :
    IBehavior<OutgoingContext>
{
    public void Invoke(OutgoingContext context, Action next)
    {
        var headers = context.OutgoingMessage.Headers;
        headers["MyCustomHeader"] = "My custom value";
        next();
    }
}

Also note that headers can only be set on the outgoing pipeline.