Interface IDispatchRouter
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
messageIDispatchMessageThe message to check.
destinationstringThe 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
messageis null.- ArgumentException
Thrown when
destinationis null or empty.
GetAvailableRoutes(IDispatchMessage, IMessageContext)
Gets all available routes for a message (for diagnostics).
IEnumerable<RouteInfo> GetAvailableRoutes(IDispatchMessage message, IMessageContext context)
Parameters
messageIDispatchMessageThe message to get routes for.
contextIMessageContextThe message context.
Returns
- IEnumerable<RouteInfo>
Information about all available routes including transport and endpoint routes.
Exceptions
- ArgumentNullException
Thrown when
messageorcontextis null.
RouteAsync(IDispatchMessage, IMessageContext, CancellationToken)
Determines both transport and endpoint routing for a message.
ValueTask<RoutingDecision> RouteAsync(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<RoutingDecision>
A RoutingDecision containing the selected transport, target endpoints, and routing metadata.
Exceptions
- ArgumentNullException
Thrown when
messageorcontextis null.