pub struct HandlerContext {
pub message_id: MessageId,
pub correlation_id: CorrelationId,
pub cancellation: CancellationToken,
pub span: Span,
}Expand description
Contextual information injected into every handler invocation.
The context carries the identifiers of the in-flight message, a
CancellationToken for cooperative cancellation, and the active
tracing::Span for distributed tracing propagation.
Fields§
§message_id: MessageIdUnique identifier of this specific message instance.
correlation_id: CorrelationIdIdentifier linking all messages in the same causal chain.
cancellation: CancellationTokenToken that is cancelled when the dispatch is aborted or timed out.
span: SpanActive tracing span at the time of dispatch.
Implementations§
Source§impl HandlerContext
impl HandlerContext
Sourcepub fn new(message_id: MessageId, correlation_id: CorrelationId) -> Self
pub fn new(message_id: MessageId, correlation_id: CorrelationId) -> Self
Creates a new context for the given message identifiers.
The CancellationToken is fresh (not yet cancelled) and the span is
captured from the current tracing context.
Sourcepub fn with_span(self, span: Span) -> Self
pub fn with_span(self, span: Span) -> Self
Overrides the tracing span. Useful when the caller manages span lifecycle explicitly.
Sourcepub fn with_cancellation(self, token: CancellationToken) -> Self
pub fn with_cancellation(self, token: CancellationToken) -> Self
Overrides the cancellation token. Use this to share a parent token with the dispatch so that cancelling the parent propagates here.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if the cancellation token has been cancelled.
Trait Implementations§
Source§impl Clone for HandlerContext
impl Clone for HandlerContext
Source§fn clone(&self) -> HandlerContext
fn clone(&self) -> HandlerContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more