Table of Contents

Class InstanceHeartbeatService

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

Background service that publishes a heartbeat for this instance to the Dapr state store on a configured interval and discovers peer instance heartbeats to populate the local knownInstances set.

Without this, ConnectionReclaimerHostedService treats every connection from a different instance ID as a candidate for reclamation — which is correct only after the peer has died. Heartbeats let live peers advertise their presence so live connections are never reclaimed.

public sealed class InstanceHeartbeatService : BackgroundService, IHostedService, IDisposable
Inheritance
InstanceHeartbeatService
Implements
Inherited Members

Constructors

InstanceHeartbeatService(DaprClient, IInstanceIdProvider, ILogger<InstanceHeartbeatService>, InstanceHeartbeatOptions, string)

public InstanceHeartbeatService(DaprClient daprClient, IInstanceIdProvider instanceIdProvider, ILogger<InstanceHeartbeatService> logger, InstanceHeartbeatOptions options, string stateStoreName)

Parameters

daprClient DaprClient
instanceIdProvider IInstanceIdProvider
logger ILogger<InstanceHeartbeatService>
options InstanceHeartbeatOptions
stateStoreName string

Fields

HeartbeatIndexKey

State-store key prefix for the heartbeat index (set of all live instance IDs).

public const string HeartbeatIndexKey = "websocketmanager/instances/_index"

Field Value

string

HeartbeatKeyPrefix

State-store key prefix for instance heartbeats.

public const string HeartbeatKeyPrefix = "websocketmanager/instances/"

Field Value

string

Methods

ExecuteAsync(CancellationToken)

This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.

protected override Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Returns

Task

A Task that represents the long running operations.

Remarks

See Worker Services in .NET for implementation guidelines.