Table of Contents

Class OrderingContextExtensions

Namespace
Excalibur.Dispatch
Assembly
Excalibur.Dispatch.Abstractions.dll

Extension methods for stamping and reading the per-message ordering sequence used by the ordering-validation middleware.

public static class OrderingContextExtensions
Inheritance
OrderingContextExtensions
Inherited Members

Remarks

The framework does not stamp this for you. Deserializing a transport payload into a concrete message type is the consumer's bridge between receiving and dispatching, and that bridge is the only place holding both the received message and the context, so it is what stamps the sequence. Call TransportOrderingMetadata.TryStampOrdering there to lift a transport's native sequence (a Kafka partition offset, an Azure Service Bus SequenceNumber) out of the received message, or call SetOrderingSequence(IMessageContext, long, string?) directly where the transport has no native monotonic sequence -- Pub/Sub among them.

The ordering-validation middleware reads the stamp via TryGetOrderingSequence(IMessageContext, out long, out string) and enforces strictly-increasing order per key. It only enforces on messages that entered an ordered receive path, which MarkOrderingEnforced(IMessageContext) records; anything else -- an outbound send, an in-process command -- passes through untouched.

Fields

DefaultOrderingKey

The ordering key used when a message is stamped with a sequence but no explicit key — a single global ordering stream.

public const string DefaultOrderingKey = "__default__"

Field Value

string

Methods

IsOrderingEnforced(IMessageContext)

Indicates whether this message arrived through a receive path where ordering is enforced.

public static bool IsOrderingEnforced(this IMessageContext context)

Parameters

context IMessageContext

The message context.

Returns

bool

true if MarkOrderingEnforced(IMessageContext) was called for this message; otherwise false, meaning ordering does not apply to it.

Exceptions

ArgumentNullException

context is null.

MarkOrderingEnforced(IMessageContext)

Records that this message arrived through a receive path where ordering is enforced.

public static void MarkOrderingEnforced(this IMessageContext context)

Parameters

context IMessageContext

The message context.

Remarks

This is what bounds the fail-closed check to the messages it is about. The middleware is registered once for the whole process and sees every dispatch, so without a marker "no sequence present" cannot be told apart from "this message was never supposed to carry one" -- and an outbound send or a plain in-process command would be rejected for lacking a sequence nothing was ever going to give it. Marking happens when the receive bridge attempts the stamp, so it records the ATTEMPT rather than its success: a message that entered an ordered path and arrived without a usable sequence is still a fault, and still fails closed.

Exceptions

ArgumentNullException

context is null.

SetOrderingSequence(IMessageContext, long, string?)

Stamps the message context with a monotonic ordering sequence (and optional ordering key) so the ordering-validation middleware can enforce strictly-increasing delivery per key.

public static void SetOrderingSequence(this IMessageContext context, long sequence, string? orderingKey = null)

Parameters

context IMessageContext

The message context.

sequence long

The transport-native monotonic sequence (e.g. Kafka offset, ASB SequenceNumber).

orderingKey string

The ordering key (partition/stream) the sequence is monotonic within. When null or empty, DefaultOrderingKey is used.

Exceptions

ArgumentNullException

context is null.

TryGetOrderingSequence(IMessageContext, out long, out string)

Attempts to read the ordering sequence and key stamped on the context.

public static bool TryGetOrderingSequence(this IMessageContext context, out long sequence, out string orderingKey)

Parameters

context IMessageContext

The message context.

sequence long

When this returns true, the stamped sequence.

orderingKey string

When this returns true, the ordering key (never empty).

Returns

bool

true if an ordering sequence was stamped (ordering enforcement applies); otherwise false (the message is unordered and passes through).

Exceptions

ArgumentNullException

context is null.