Class PoisonMessageMiddleware
- Namespace
- Excalibur.Dispatch.ErrorHandling
- Assembly
- Excalibur.Dispatch.dll
Middleware that detects and handles poison messages during dispatch processing.
public sealed class PoisonMessageMiddleware : IDispatchMiddleware, IDisposable
- Inheritance
-
PoisonMessageMiddleware
- Implements
- Inherited Members
- Extension Methods
Constructors
PoisonMessageMiddleware(IPoisonMessageDetector, IPoisonMessageHandler, IOptions<PoisonMessageOptions>, ILogger<PoisonMessageMiddleware>)
Initializes a new instance of the PoisonMessageMiddleware class.
public PoisonMessageMiddleware(IPoisonMessageDetector poisonDetector, IPoisonMessageHandler poisonHandler, IOptions<PoisonMessageOptions> options, ILogger<PoisonMessageMiddleware> logger)
Parameters
poisonDetectorIPoisonMessageDetectorpoisonHandlerIPoisonMessageHandleroptionsIOptions<PoisonMessageOptions>loggerILogger<PoisonMessageMiddleware>
Properties
Stage
Gets the stage at which this middleware should execute in the pipeline.
public DispatchMiddlewareStage? Stage { get; }
Property Value
- DispatchMiddlewareStage?
The current Stage value.
Methods
Dispose()
Disposes the middleware and releases the activity source.
public void Dispose()
InvokeAsync(IDispatchMessage, IMessageContext, DispatchRequestDelegate, CancellationToken)
Processes the message within the middleware pipeline.
[UnconditionalSuppressMessage("AotAnalysis", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = "Poison message handling relies on dynamic serialization and is not supported for AOT scenarios.")]
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "Poison message handling relies on serialization of known message types registered at startup.")]
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.