Table of Contents

Interface IDispatchRouter

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

Unified router that handles both transport selection and endpoint routing.

public interface IDispatchRouter
Extension Methods

Examples

// The IDispatchRouter is typically used internally by the middleware.
// Configure routing via the fluent builder:
services.AddDispatch(dispatch =>
{
    dispatch.UseRouting(routing =>
    {
        routing.Transport
            .Route<OrderCreated>().To("rabbitmq")
            .Default("local");

        routing.Endpoints
            .Route<OrderCreated>()
                .To("billing-service", "inventory-service");
    });
});

Remarks

The dispatch router combines ITransportSelector and IEndpointRouter into a single interface that returns a complete RoutingDecision containing both the selected transport and target endpoints.

This is the primary routing interface used by RoutingMiddleware to make routing decisions for messages in the dispatch pipeline.

Methods

CanRouteTo(IDispatchMessage, string)

Checks if the router can route to a specific destination.

bool CanRouteTo(IDispatchMessage message, string destination)

Parameters

message IDispatchMessage

The message to check.

destination string

The destination name (transport or endpoint).

Returns

bool

true if the destination is configured as either a transport or an endpoint for the message; otherwise, false.

Exceptions

ArgumentNullException

Thrown when message is null.

ArgumentException

Thrown when destination is null or empty.

GetAvailableRoutes(IDispatchMessage, IMessageContext)

Gets all available routes for a message (for diagnostics).

IEnumerable<RouteInfo> GetAvailableRoutes(IDispatchMessage message, IMessageContext context)

Parameters

message IDispatchMessage

The message to get routes for.

context IMessageContext

The message context.

Returns

IEnumerable<RouteInfo>

Information about all available routes including transport and endpoint routes.

Exceptions

ArgumentNullException

Thrown when message or context is null.

RouteAsync(IDispatchMessage, IMessageContext, CancellationToken)

Determines both transport and endpoint routing for a message.

ValueTask<RoutingDecision> RouteAsync(IDispatchMessage message, IMessageContext context, CancellationToken cancellationToken)

Parameters

message IDispatchMessage

The message to route.

context IMessageContext

The message context containing metadata and state.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<RoutingDecision>

A RoutingDecision containing the selected transport, target endpoints, and routing metadata.

Exceptions

ArgumentNullException

Thrown when message or context is null.