Table of Contents

Class CorrelationManager

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

Manages correlation between request and response messages.

public sealed class CorrelationManager : ICorrelationManager, IDisposable
Inheritance
CorrelationManager
Implements
Inherited Members
Extension Methods

Constructors

CorrelationManager(ILogger<CorrelationManager>)

Creates a new correlation manager.

public CorrelationManager(ILogger<CorrelationManager> logger)

Parameters

logger ILogger<CorrelationManager>

Logger for diagnostics.

Properties

PendingCorrelationIds

Gets all pending correlation IDs.

public IReadOnlyCollection<Guid> PendingCorrelationIds { get; }

Property Value

IReadOnlyCollection<Guid>

PendingRequestCount

Gets the number of pending requests.

public int PendingRequestCount { get; }

Property Value

int

Methods

CancelRequest(Guid)

Cancels a pending request.

public bool CancelRequest(Guid correlationId)

Parameters

correlationId Guid

The correlation ID of the request to cancel.

Returns

bool

True if the request was found and cancelled; otherwise, false.

Dispose()

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

public void Dispose()

RegisterRequest<TResponse>(IRequestMessage<TResponse>, TimeSpan, CancellationToken)

Registers a request and returns a task that completes when the response arrives.

public CorrelationContext<TResponse> RegisterRequest<TResponse>(IRequestMessage<TResponse> request, TimeSpan timeout, CancellationToken cancellationToken = default) where TResponse : IResponseMessage

Parameters

request IRequestMessage<TResponse>

The request message being sent.

timeout TimeSpan

The timeout for waiting for the response.

cancellationToken CancellationToken

Cancellation token.

Returns

CorrelationContext<TResponse>

A correlation context that can be used to wait for the response.

Type Parameters

TResponse

The expected response type.

TryCompleteRequest(IResponseMessage)

Attempts to complete a pending request with the given response.

public bool TryCompleteRequest(IResponseMessage response)

Parameters

response IResponseMessage

The response message received.

Returns

bool

True if a matching pending request was found and completed; otherwise, false.

Events

RequestTimedOut

Occurs when a request times out.

public event EventHandler<CorrelationTimeoutEventArgs>? RequestTimedOut

Event Type

EventHandler<CorrelationTimeoutEventArgs>