Interface IDeadLetterQueue
- Namespace
- DotCompute.Abstractions.Messaging
- Assembly
- DotCompute.Abstractions.dll
Stores messages that could not be processed successfully.
public interface IDeadLetterQueue : IDisposable
- Inherited Members
- Extension Methods
Remarks
Dead letter queues capture messages that have failed processing due to:
- TTL expiration
- Maximum retry count exceeded
- Processing errors
- Validation failures
- Missing handlers
Messages in the DLQ can be inspected, reprocessed, or archived.
Properties
Count
Gets the current number of entries in the dead letter queue.
int Count { get; }
Property Value
MaxCapacity
Gets the maximum capacity of the dead letter queue.
int MaxCapacity { get; }
Property Value
Name
Gets the queue name.
string Name { get; }
Property Value
TotalDeadLettered
Gets the total number of messages ever dead-lettered.
long TotalDeadLettered { get; }
Property Value
Methods
Clear()
Clears all entries from the dead letter queue.
int Clear()
Returns
- int
Number of entries removed.
EnqueueAsync<TMessage>(TMessage, DeadLetterReason, string?, Exception?, int, string?, IReadOnlyDictionary<string, string>?, CancellationToken)
Adds a message to the dead letter queue.
Task<DeadLetterEntry> EnqueueAsync<TMessage>(TMessage message, DeadLetterReason reason, string? errorMessage = null, Exception? exception = null, int attemptCount = 1, string? sourceQueue = null, IReadOnlyDictionary<string, string>? metadata = null, CancellationToken cancellationToken = default) where TMessage : IRingKernelMessage
Parameters
messageTMessageThe failed message.
reasonDeadLetterReasonWhy the message was dead-lettered.
errorMessagestringOptional error description.
exceptionExceptionOptional exception that caused the failure.
attemptCountintNumber of processing attempts.
sourceQueuestringName of the source queue.
metadataIReadOnlyDictionary<string, string>Optional custom metadata.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DeadLetterEntry>
The created dead letter entry.
Type Parameters
TMessageThe message type.
GetEntries(Func<DeadLetterEntry, bool>?, int)
Gets all entries matching the specified filter.
IReadOnlyList<DeadLetterEntry> GetEntries(Func<DeadLetterEntry, bool>? predicate = null, int maxResults = 100)
Parameters
predicateFunc<DeadLetterEntry, bool>Optional filter predicate.
maxResultsintMaximum number of results.
Returns
- IReadOnlyList<DeadLetterEntry>
Matching dead letter entries.
GetEntriesByReason(DeadLetterReason, int)
Gets entries by dead letter reason.
IReadOnlyList<DeadLetterEntry> GetEntriesByReason(DeadLetterReason reason, int maxResults = 100)
Parameters
reasonDeadLetterReasonThe reason to filter by.
maxResultsintMaximum number of results.
Returns
- IReadOnlyList<DeadLetterEntry>
Matching dead letter entries.
GetEntriesByTimeRange(DateTimeOffset, DateTimeOffset, int)
Gets entries within a time range.
IReadOnlyList<DeadLetterEntry> GetEntriesByTimeRange(DateTimeOffset startTime, DateTimeOffset endTime, int maxResults = 100)
Parameters
startTimeDateTimeOffsetStart time (inclusive).
endTimeDateTimeOffsetEnd time (inclusive).
maxResultsintMaximum number of results.
Returns
- IReadOnlyList<DeadLetterEntry>
Matching dead letter entries.
GetStatistics()
Gets statistics about the dead letter queue.
DeadLetterStatistics GetStatistics()
Returns
- DeadLetterStatistics
Dead letter queue statistics.
Remove(Guid)
Removes an entry by its ID.
bool Remove(Guid entryId)
Parameters
entryIdGuidThe entry ID to remove.
Returns
- bool
True if the entry was found and removed.
RemoveWhere(Func<DeadLetterEntry, bool>)
Removes all entries matching the predicate.
int RemoveWhere(Func<DeadLetterEntry, bool> predicate)
Parameters
predicateFunc<DeadLetterEntry, bool>Filter for entries to remove.
Returns
- int
Number of entries removed.
TryDequeue(out DeadLetterEntry?)
Attempts to dequeue an entry from the dead letter queue.
bool TryDequeue(out DeadLetterEntry? entry)
Parameters
entryDeadLetterEntryThe dequeued entry, or null if empty.
Returns
- bool
True if an entry was dequeued.
TryPeek(out DeadLetterEntry?)
Peeks at the next entry without removing it.
bool TryPeek(out DeadLetterEntry? entry)
Parameters
entryDeadLetterEntryThe peeked entry, or null if empty.
Returns
- bool
True if an entry exists.
Events
MessageDeadLettered
Occurs when a message is added to the dead letter queue.
event EventHandler<DeadLetterEventArgs>? MessageDeadLettered