Table of Contents

Class TransportRouterMiddleware

Namespace
Excalibur.Dispatch.Transport
Assembly
Excalibur.Dispatch.dll

Middleware that validates transport messages and ensures message kinds are accepted by the binding.

public sealed class TransportRouterMiddleware : IDispatchMiddleware
Inheritance
TransportRouterMiddleware
Implements
Inherited Members
Extension Methods

Remarks

This middleware validates that messages received via transport adapters match the binding's accepted message kinds. Transport binding resolution is handled by the ITransportContextProvider in the Dispatcher BEFORE middleware invocation.

The binding is retrieved from the context where it was stored by the Dispatcher during transport context resolution. Pipeline profile selection also happens in the Dispatcher, before the middleware chain is constructed.

Constructors

TransportRouterMiddleware(ILogger<TransportRouterMiddleware>)

Middleware that validates transport messages and ensures message kinds are accepted by the binding.

public TransportRouterMiddleware(ILogger<TransportRouterMiddleware> logger)

Parameters

logger ILogger<TransportRouterMiddleware>

Remarks

This middleware validates that messages received via transport adapters match the binding's accepted message kinds. Transport binding resolution is handled by the ITransportContextProvider in the Dispatcher BEFORE middleware invocation.

The binding is retrieved from the context where it was stored by the Dispatcher during transport context resolution. Pipeline profile selection also happens in the Dispatcher, before the middleware chain is constructed.

Properties

ApplicableMessageKinds

Gets the message kinds that this middleware applies.

public MessageKinds ApplicableMessageKinds { get; }

Property Value

MessageKinds

The set of message kinds this middleware applies to.

Remarks

Specifies which types of messages this middleware should process. The pipeline filters middleware based on these flags, ensuring only relevant middleware processes each message. This improves performance and allows middleware to specialize in handling specific message types. If not implemented, defaults to All for backward compatibility.

Stage

Gets the pipeline stage where this middleware should execute.

public DispatchMiddlewareStage? Stage { get; }

Property Value

DispatchMiddlewareStage?

The pipeline stage for this middleware.

Remarks

The stage determines the execution order of middleware in the pipeline. If null, the middleware will be registered at the end of the pipeline. Stages are processed in numeric order, allowing fine-grained control over middleware execution sequence.

Methods

InvokeAsync(IDispatchMessage, IMessageContext, DispatchRequestDelegate, CancellationToken)

Processes the message within the middleware pipeline.

[UnconditionalSuppressMessage("AOT", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "DetermineMessageKind uses reflection to check message interfaces, but this is acceptable in transport routing middleware as it operates on message types that are registered at startup and preserved through DI. Message types in messaging systems are known at compile time and registered explicitly.")]
public ValueTask<IMessageResult> InvokeAsync(IDispatchMessage message, IMessageContext context, DispatchRequestDelegate nextDelegate, CancellationToken cancellationToken)

Parameters

message IDispatchMessage

The message being processed.

context IMessageContext

The message context containing metadata and processing state.

nextDelegate DispatchRequestDelegate

The delegate to invoke the next middleware in the pipeline.

cancellationToken CancellationToken

The cancellation token to observe.

Returns

ValueTask<IMessageResult>

A ValueTask<TResult> representing the result of message processing, potentially modified by this middleware. ValueTask can avoid allocating a Task for a synchronously completed result; other dispatch work can still allocate.

Remarks

Implementations can execute logic before calling nextDelegate, after calling it, or both. To short-circuit the pipeline, don't call nextDelegate and return an appropriate result. The context can be used to share data between middleware components. Respect the cancellation token to support timeouts and graceful shutdown.

Exceptions

ArgumentNullException

Thrown when message, context, or nextDelegate is null.

OperationCanceledException

Thrown when the operation is cancelled.