Interface IEndpointRouter
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
messageIDispatchMessageThe message to check.
endpointstringThe endpoint name to verify.
Returns
Exceptions
- ArgumentNullException
Thrown when
messageis null.- ArgumentException
Thrown when
endpointis null or empty.
GetEndpointRoutes(IDispatchMessage, IMessageContext)
Gets all configured endpoint routes for diagnostic purposes.
IEnumerable<RouteInfo> GetEndpointRoutes(IDispatchMessage message, IMessageContext context)
Parameters
messageIDispatchMessageThe message to get routes for.
contextIMessageContextThe message context.
Returns
- IEnumerable<RouteInfo>
Information about all configured endpoint routes, including rule names, destinations, and priorities.
Exceptions
- ArgumentNullException
Thrown when
messageorcontextis 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
messageIDispatchMessageThe message to route.
contextIMessageContextThe message context containing metadata and state.
cancellationTokenCancellationTokenToken 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
messageorcontextis null.