Class ContractVersionCheckMiddleware
- Namespace
- Excalibur.Dispatch.Middleware.Versioning
- Assembly
- Excalibur.Dispatch.dll
Middleware responsible for validating event contract versions and compatibility to ensure safe evolution of event schemas in distributed systems.
public sealed class ContractVersionCheckMiddleware : IDispatchMiddleware
- Inheritance
-
ContractVersionCheckMiddleware
- Implements
- Inherited Members
- Extension Methods
Remarks
This middleware applies specifically to Event messages to enforce contract versioning and backward/forward compatibility rules. It:
- Validates event schema versions against supported versions
- Enforces semantic versioning compatibility rules
- Handles version migration and transformation
- Provides warnings for deprecated event versions
- Blocks processing of incompatible event versions
- Integrates with schema registries for centralized version management
Events are critical for system integration and require careful version management to prevent breaking changes from causing cascading failures across services.
Constructors
ContractVersionCheckMiddleware(IOptions<ContractVersionCheckOptions>, IContractVersionService, ILogger<ContractVersionCheckMiddleware>)
Initializes a new instance of the ContractVersionCheckMiddleware class. Creates a new contract version check middleware instance.
public ContractVersionCheckMiddleware(IOptions<ContractVersionCheckOptions> options, IContractVersionService versionService, ILogger<ContractVersionCheckMiddleware> logger)
Parameters
optionsIOptions<ContractVersionCheckOptions>Configuration options for contract version checking.
versionServiceIContractVersionServiceService for managing contract versions and compatibility.
loggerILogger<ContractVersionCheckMiddleware>Logger for diagnostic information.
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.
public ValueTask<IMessageResult> InvokeAsync(IDispatchMessage message, IMessageContext context, DispatchRequestDelegate nextDelegate, CancellationToken cancellationToken)
Parameters
messageIDispatchMessageThe message being processed.
contextIMessageContextThe message context containing metadata and processing state.
nextDelegateDispatchRequestDelegateThe delegate to invoke the next middleware in the pipeline.
cancellationTokenCancellationTokenThe 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.