Class DeadLetterQueue
- Namespace
- DotCompute.Core.Messaging
- Assembly
- DotCompute.Core.dll
Thread-safe implementation of the dead letter queue.
public sealed class DeadLetterQueue : IDeadLetterQueue, IDisposable
- Inheritance
-
DeadLetterQueue
- Implements
- Inherited Members
- Extension Methods
Constructors
DeadLetterQueue(string, DeadLetterQueueOptions, ILogger<DeadLetterQueue>)
Creates a new dead letter queue.
public DeadLetterQueue(string name, DeadLetterQueueOptions options, ILogger<DeadLetterQueue> logger)
Parameters
namestringThe queue name.
optionsDeadLetterQueueOptionsConfiguration options.
loggerILogger<DeadLetterQueue>Logger for diagnostics.
Properties
Count
Gets the current number of entries in the dead letter queue.
public int Count { get; }
Property Value
MaxCapacity
Gets the maximum capacity of the dead letter queue.
public int MaxCapacity { get; }
Property Value
Name
Gets the queue name.
public string Name { get; }
Property Value
TotalDeadLettered
Gets the total number of messages ever dead-lettered.
public long TotalDeadLettered { get; }
Property Value
Methods
Clear()
Clears all entries from the dead letter queue.
public int Clear()
Returns
- int
Number of entries removed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
EnqueueAsync<TMessage>(TMessage, DeadLetterReason, string?, Exception?, int, string?, IReadOnlyDictionary<string, string>?, CancellationToken)
Adds a message to the dead letter queue.
public 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.
public 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.
public 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.
public 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.
public DeadLetterStatistics GetStatistics()
Returns
- DeadLetterStatistics
Dead letter queue statistics.
Remove(Guid)
Removes an entry by its ID.
public 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.
public 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.
public 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.
public 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.
public event EventHandler<DeadLetterEventArgs>? MessageDeadLettered