Interface IOutboxLock
- Namespace
- Stratara.Abstractions.Outbox
- Assembly
- Stratara.Abstractions.dll
Mutual-exclusion primitive that coordinates outbox-drain access across multiple host instances. The outbox worker calls TryAcquireAsync(TimeSpan, CancellationToken) at the start of every polling cycle; only the instance that receives a non-null handle proceeds to drain. Other instances skip the cycle and re-attempt at the next poll interval.
public interface IOutboxLock
- Extension Methods
Remarks
The default implementation registered by AddOutboxWorker is a no-op that always
grants the lock, preserving the historical single-instance assumption. Consumers that
run more than one outbox-worker replica opt in to a real distributed lock (for example
via AddRedisOutboxLock), which acquires a leased key in shared infrastructure
(Redis) and auto-releases after the configured lease expires.
Methods
TryAcquireAsync(TimeSpan, CancellationToken)
Attempts to acquire the outbox-drain lock with the requested lease.
Task<IOutboxLockHandle?> TryAcquireAsync(TimeSpan lease, CancellationToken cancellationToken = default)
Parameters
leaseTimeSpanMaximum time the lock is held before the underlying store auto-releases it. Should be at least as long as the worst-case drain duration; otherwise the lock may expire mid-cycle and a peer can start a concurrent drain.
cancellationTokenCancellationTokenPropagated to the underlying lock store.
Returns
- Task<IOutboxLockHandle>
A disposable handle when the lock was granted; null when another instance currently holds the lock. The caller MUST dispose the handle when the critical section completes so the lock is released early; failure to do so leaves the lock in place until the lease elapses.