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.

Replying to a Message

Component:
NServiceBus
NuGet Package:
NServiceBus 10.x

The simplest way to reply to a message is using the Reply method:

public Task Handle(RequestDataMessage message, IMessageHandlerContext context)
{
    // Create a response message:
    var response = new DataResponseMessage
    {
        DataId = message.DataId,
        String = message.String
    };

    // Reply sends a new message to the return address on the message being handled.
    return context.Reply(response);
}

Only use a reply when implementing the Request-Response pattern (also called the Full Duplex pattern). In this pattern, the originator of the message should expect a response message and have a handler for it. For examples and more information, see the Full Duplex Sample and the article Callbacks.

When using the Publish-Subscribe pattern, an endpoint handling an event shouldn't use Reply. This is because the publisher might not expect a reply and has no message handler for the replied message.

The reply address is controlled by the sender of the message being replied to. See how to influence the reply behavior when sending messages.

Influencing the reply behavior

A sender of a reply can influence how the requester will behave when continuing the conversation (replying to a reply). It can request a reply to go to itself (not any other instance of the same endpoint)

var options = new ReplyOptions();
options.RouteReplyToThisInstance();
var myMessage = new MyMessage();
await context.Reply(myMessage, options);

or explicitly to any instance of the endpoint (which overrides the public reply address setting)

var options = new ReplyOptions();
options.RouteReplyToAnyInstance();
var myMessage = new MyMessage();
await context.Reply(myMessage, options);

It can also request the reply to be routed to a specified transport address.

var options = new ReplyOptions();
options.RouteReplyTo("MyDestination");
var myMessage = new MyMessage();
await context.Reply(myMessage, options);