Interface ITransportSelector
Service responsible for selecting the appropriate transport (message bus) for a message.
public interface ITransportSelector
- Extension Methods
Examples
services.AddDispatch(dispatch =>
{
dispatch.UseRouting(routing =>
{
routing.Transport
.Route<OrderCreated>().To("rabbitmq")
.Route<PaymentProcessed>().To("kafka")
.Default("local");
});
});
Remarks
The transport selector determines which message bus should handle a given message. Common transports include "local" (in-process), "rabbitmq", "kafka", "azureservicebus", etc.
This interface replaces the former IRouterService with clearer naming that
distinguishes transport selection from endpoint routing.
Methods
GetAvailableTransports(Type)
Gets all available transports that can handle the specified message type.
IEnumerable<string> GetAvailableTransports(Type messageType)
Parameters
messageTypeTypeThe type of message to check.
Returns
- IEnumerable<string>
A collection of transport names that have rules configured for the message type, plus the default transport.
Exceptions
- ArgumentNullException
Thrown when
messageTypeis null.
SelectTransportAsync(IDispatchMessage, IMessageContext, CancellationToken)
Selects the transport for a message based on configured routing rules.
ValueTask<string> SelectTransportAsync(IDispatchMessage message, IMessageContext context, CancellationToken cancellationToken)
Parameters
messageIDispatchMessageThe message to route.
contextIMessageContextThe message context containing metadata and state.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
Exceptions
- ArgumentNullException
Thrown when
messageorcontextis null.