Table of Contents

Class RoutingDecision

Namespace
Excalibur.Dispatch.Routing
Assembly
Excalibur.Dispatch.Abstractions.dll

Result of routing evaluation containing both transport and endpoint decisions.

public sealed record RoutingDecision : IEquatable<RoutingDecision>
Inheritance
RoutingDecision
Implements
Inherited Members
Extension Methods

Examples

// Creating a successful routing decision
var decision = RoutingDecision.Success(
    transport: "rabbitmq",
    endpoints: new[] { "billing-service", "inventory-service" },
    matchedRules: new[] { "order-transport-rule", "order-endpoint-rule" });

// Creating a failure routing decision
var failed = RoutingDecision.Failure("No matching routing rules found");

// Checking the result
if (decision.IsSuccess)
{
    Console.WriteLine($"Route to {decision.Transport} -> {string.Join(", ", decision.Endpoints)}");
}

Remarks

The routing decision encapsulates the complete outcome of message routing, including which transport (message bus) to use and which endpoints (services) should receive the message.

Use the factory methods Success(string, IReadOnlyList<string>, IReadOnlyList<string>?) and Failure(string) to create instances with appropriate initialization.

Properties

Endpoints

Gets the target endpoints (e.g., "billing-service", "inventory-service").

public required IReadOnlyList<string> Endpoints { get; init; }

Property Value

IReadOnlyList<string>

A read-only list of endpoint names. May be empty for local-only routing.

FailureReason

Gets the failure reason if routing failed.

public string? FailureReason { get; init; }

Property Value

string

A description of why routing failed, or null if routing succeeded.

IsSuccess

Gets a value indicating whether routing succeeded.

public bool IsSuccess { get; }

Property Value

bool

true if a transport was selected; otherwise, false.

Local

Gets a cached singleton for local-only routing (no transport, no endpoints).

public static RoutingDecision Local { get; }

Property Value

RoutingDecision

Remarks

Avoids allocating a new RoutingDecision record per dispatch for the common case of local-only message handling. Follows the CompletedTask / Empty<T>() pattern of caching frequently-used immutable values.

MatchedRules

Gets the names of routing rules that matched (for diagnostics).

public IReadOnlyList<string> MatchedRules { get; init; }

Property Value

IReadOnlyList<string>

A read-only list of rule names that contributed to this routing decision.

Transport

Gets the selected transport (e.g., "local", "rabbitmq", "kafka").

public required string Transport { get; init; }

Property Value

string

The transport name. Empty string indicates routing failure.

Methods

Failure(string)

Creates a failed routing decision.

public static RoutingDecision Failure(string reason)

Parameters

reason string

A description of why routing failed.

Returns

RoutingDecision

A new RoutingDecision indicating failure.

Exceptions

ArgumentException

Thrown when reason is null or empty.

Success(string, IReadOnlyList<string>, IReadOnlyList<string>?)

Creates a successful routing decision.

public static RoutingDecision Success(string transport, IReadOnlyList<string> endpoints, IReadOnlyList<string>? matchedRules = null)

Parameters

transport string

The selected transport name.

endpoints IReadOnlyList<string>

The target endpoint names.

matchedRules IReadOnlyList<string>

Optional list of matched rule names for diagnostics.

Returns

RoutingDecision

A new RoutingDecision indicating success.

Exceptions

ArgumentException

Thrown when transport is null or empty.

ArgumentNullException

Thrown when endpoints is null.