Table of Contents

Interface IEndpointRouter

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

Service responsible for routing messages to target endpoints (services).

public interface IEndpointRouter
Extension Methods

Examples

services.AddDispatch(dispatch =>
{
    dispatch.UseRouting(routing =>
    {
        routing.Endpoints
            .Route<OrderCreated>()
                .To("billing-service", "inventory-service")
                .When(msg => msg.Amount > 1000).AlsoTo("fraud-detection");
    });
});

Remarks

The endpoint router determines which services should receive a message. This enables content-based routing, multicast delivery, and conditional routing based on message content, headers, or other criteria.

This interface replaces the former IMessageRouter with clearer naming that distinguishes endpoint routing from transport selection.

Methods

CanRouteToEndpoint(IDispatchMessage, string)

Checks if a message can be routed to the specified endpoint.

bool CanRouteToEndpoint(IDispatchMessage message, string endpoint)

Parameters

message IDispatchMessage

The message to check.

endpoint string

The endpoint name to verify.

Returns

bool

true if any routing rule targets the specified endpoint; otherwise, false.

Exceptions

ArgumentNullException

Thrown when message is null.

ArgumentException

Thrown when endpoint is null or empty.

GetEndpointRoutes(IDispatchMessage, IMessageContext)

Gets all configured endpoint routes for diagnostic purposes.

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

Parameters

message IDispatchMessage

The message to get routes for.

context IMessageContext

The message context.

Returns

IEnumerable<RouteInfo>

Information about all configured endpoint routes, including rule names, destinations, and priorities.

Exceptions

ArgumentNullException

Thrown when message or context is null.

RouteToEndpointsAsync(IDispatchMessage, IMessageContext, CancellationToken)

Routes a message to its target endpoints based on configured routing rules.

ValueTask<IReadOnlyList<string>> RouteToEndpointsAsync(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<IReadOnlyList<string>>

A list of endpoint names that should receive the message. Returns an empty list if no matching rules are found and no fallback is configured.

Exceptions

ArgumentNullException

Thrown when message or context is null.