Table of Contents

Class MessageTtlManager

Namespace
DotCompute.Core.Messaging
Assembly
DotCompute.Core.dll

Manages message TTL enforcement and expiration handling.

public sealed class MessageTtlManager : IMessageTtlManager, IAsyncDisposable
Inheritance
MessageTtlManager
Implements
Inherited Members

Constructors

MessageTtlManager(ILogger<MessageTtlManager>, TimeSpan?, TimeSpan?)

Creates a new message TTL manager.

public MessageTtlManager(ILogger<MessageTtlManager> logger, TimeSpan? checkInterval = null, TimeSpan? defaultTtl = null)

Parameters

logger ILogger<MessageTtlManager>

Logger for diagnostics.

checkInterval TimeSpan?

How often to check for expired messages. Default: 1 second.

defaultTtl TimeSpan?

Default TTL for messages without explicit TTL. Default: 30 seconds.

Properties

ExpiredCount

Gets the number of messages that have expired while being tracked.

public long ExpiredCount { get; }

Property Value

long

TrackedCount

Gets the number of messages currently being tracked.

public int TrackedCount { get; }

Property Value

int

Methods

CancelTracking(Guid)

Stops tracking a message.

public bool CancelTracking(Guid trackingId)

Parameters

trackingId Guid

The tracking ID from TrackAsync<TMessage>(TMessage, Func<TMessage, Task>, CancellationToken).

Returns

bool

True if tracking was cancelled.

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

GetRemainingTtl<TMessage>(TMessage)

Gets the remaining TTL for a message.

public TimeSpan? GetRemainingTtl<TMessage>(TMessage message) where TMessage : IRingKernelMessage

Parameters

message TMessage

The message to check.

Returns

TimeSpan?

Remaining time, or TimeSpan.Zero if expired, or null if no TTL.

Type Parameters

TMessage

The message type.

IsExpired<TMessage>(TMessage)

Checks if a message has expired.

public bool IsExpired<TMessage>(TMessage message) where TMessage : IRingKernelMessage

Parameters

message TMessage

The message to check.

Returns

bool

True if the message has expired.

Type Parameters

TMessage

The message type.

TrackAsync<TMessage>(TMessage, Func<TMessage, Task>, CancellationToken)

Tracks a message for TTL enforcement.

public Task<Guid> TrackAsync<TMessage>(TMessage message, Func<TMessage, Task> onExpired, CancellationToken cancellationToken = default) where TMessage : IRingKernelMessage

Parameters

message TMessage

The message to track.

onExpired Func<TMessage, Task>

Callback when the message expires.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Guid>

A tracking ID that can be used to cancel tracking.

Type Parameters

TMessage

The message type.

Events

MessageExpired

Occurs when a tracked message expires.

public event EventHandler<MessageExpiredEventArgs>? MessageExpired

Event Type

EventHandler<MessageExpiredEventArgs>