Table of Contents

Class ApiLifecyclePublisher

Namespace
Virtufin.WebSocketManager.Services
Assembly
Virtufin.WebSocketManager.dll

Publishes connection lifecycle events to the virtufin-api's system-events topic. Events are CloudEvents v1.0 envelopes with the WSM's URN as the source. The publisher is best-effort: failures are logged but never propagated, so an unreachable API does not break the WSM's local connection state machine.

public class ApiLifecyclePublisher
Inheritance
ApiLifecyclePublisher
Inherited Members

Constructors

ApiLifecyclePublisher(ILogger<ApiLifecyclePublisher>, PubsubClient)

public ApiLifecyclePublisher(ILogger<ApiLifecyclePublisher> logger, Pubsub.PubsubClient pubsub)

Parameters

logger ILogger<ApiLifecyclePublisher>
pubsub Pubsub.PubsubClient

Methods

PublishErrorAsync(WebSocketConnection, Exception, CancellationToken)

Fires a connection.error event with the exception context BEFORE any state transition. Subscribers can use this for diagnostics; the subsequent state transition event carries the recovery action.

public Task PublishErrorAsync(WebSocketConnection connection, Exception ex, CancellationToken cancellationToken = default)

Parameters

connection WebSocketConnection
ex Exception
cancellationToken CancellationToken

Returns

Task

PublishIfChangedAsync(WebSocketConnection, ConnectionStatus, int?, CancellationToken)

Fires a connection.* event when the connection's status changes. Returns immediately. If connection.Status already equals newStatus, no event is published.

public Task PublishIfChangedAsync(WebSocketConnection connection, ConnectionStatus newStatus, int? attempt = null, CancellationToken cancellationToken = default)

Parameters

connection WebSocketConnection
newStatus ConnectionStatus
attempt int?

For Reconnecting events, the reconnect attempt number about to be made (spec requires this field in the data payload). Ignored for other status values. Note: the WSM fires exactly one Reconnecting event before entering the retry loop, not one per attempt -- so this is always the first attempt number today, not a live per-attempt counter.

cancellationToken CancellationToken

Returns

Task