AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/samples/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.

Command routing

Component:
NServiceBus
NuGet Package:
NServiceBus 10.x

The sample demonstrates basic command routing between endpoints.

Running the project

  1. Start all the projects by hitting F5.
  2. In the Sender's console window send some orders by pressing S
  3. In the Sender's console window cancel some orders by pressing C
  4. Both messages are sent to the Receiver which logs a message

Code walk-through

Endpoint configuration command routing

Command routing can be specified in the endpoint configuration, as the sample does for the PlaceOrder command.

var routing = endpointConfiguration.UseTransport(new LearningTransport());

routing.RouteToEndpoint(
    messageType: typeof(PlaceOrder),
    destination: "Samples.CommandRouting.Receiver"
);

Whenever the Sender sends a PlaceOrder command it does not need to specify a destination. This is the preferred method for routing commands.

var command = new PlaceOrder
{
    OrderId = orderId,
    Value = value
};

await messageSession.Send(command);
Console.WriteLine($"Order placed: {orderId}");

Per-message command routing

In special circumstances, a command can be routed when it is sent.

Whenever the Sender sends a CancelOrder command it specifies the destination endpoint.

var command = new CancelOrder
{
    OrderId = orderId
};

await messageSession.Send("Samples.CommandRouting.Receiver", command);
Console.WriteLine($"Order canceled: {orderId}");