Table of Contents

Interface IClaimableDeduplicator

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

An optional capability for IInMemoryDeduplicator implementations that support an atomic claim-before-execute idempotency protocol, the in-memory analogue of IClaimableInboxStore.

public interface IClaimableDeduplicator
Extension Methods

Remarks

This is a segregated capability interface (composition, NOT inheritance of IInMemoryDeduplicator) so that IInMemoryDeduplicator stays within the Interface Segregation threshold. Deduplicators that support atomic claiming implement this interface in addition to IInMemoryDeduplicator.

The protocol replaces the racy check-then-act of a separate IsDuplicateAsync(string, TimeSpan, CancellationToken) followed by a later mark: claim atomically before the handler runs, and release the claim if the handler fails so a redelivery can re-admit the message.

Methods

ReleaseAsync(string, LeaseToken, CancellationToken)

Releases a previously acquired claim by removing the message id, so that a redelivery of the same message can be re-admitted.

Task<bool> ReleaseAsync(string messageId, LeaseToken claim, CancellationToken cancellationToken)

Parameters

messageId string

The unique identifier of the message.

claim LeaseToken

The term returned by TryClaimAsync(string, TimeSpan, CancellationToken).

cancellationToken CancellationToken

Token to monitor for cancellation requests.

Returns

Task<bool>

true if the caller still held the claim and it was removed; false if the claim had already lapsed and been taken by another caller, or was never present.

Remarks

Call this when the handler fails after a successful TryClaimAsync(string, TimeSpan, CancellationToken). Releasing an already-removed or never-claimed message id is a no-op.

Release names what it releases. The claim carries an expiry, so a caller that outran it may find the id already re-claimed by a second caller. Removing by id alone would delete that live claim and admit the same message twice; presenting the term makes releasing someone else's claim inexpressible.

TryClaimAsync(string, TimeSpan, CancellationToken)

Atomically claims a message id if and only if it is not already present, marking it for the specified retention window.

Task<LeaseToken?> TryClaimAsync(string messageId, TimeSpan expiry, CancellationToken cancellationToken)

Parameters

messageId string

The unique identifier of the message.

expiry TimeSpan

How long to remember the message id once claimed.

cancellationToken CancellationToken

Token to monitor for cancellation requests.

Returns

Task<LeaseToken?>

A LeaseToken identifying this holder if the caller created the claim (first writer, proceed to handle); null if the message id is already present (duplicate, skip).

Remarks

This is a single atomic "first writer wins" operation. A successful claim doubles as the dedup marker: on handler success no further call is required; on handler failure call ReleaseAsync(string, LeaseToken, CancellationToken) to remove it.