Table of Contents

Class WebSocketService

Namespace
Virtufin.WebSocketManager.Services
Assembly
Virtufin.WebSocketManager.dll
public class WebSocketService : IWebSocketService
Inheritance
WebSocketService
Implements
Inherited Members

Constructors

WebSocketService(IWebSocketConnectionStore, IWebSocketClientWrapper, IDaprPublisher, IWebSocketUrlValidator, ILogger<WebSocketService>)

public WebSocketService(IWebSocketConnectionStore connectionStore, IWebSocketClientWrapper webSocketClient, IDaprPublisher daprPublisher, IWebSocketUrlValidator urlValidator, ILogger<WebSocketService> logger)

Parameters

connectionStore IWebSocketConnectionStore
webSocketClient IWebSocketClientWrapper
daprPublisher IDaprPublisher
urlValidator IWebSocketUrlValidator
logger ILogger<WebSocketService>

Methods

ConnectAsync(string, bool, CancellationToken)

public Task<WebSocketConnection> ConnectAsync(string url, bool autoReconnect, CancellationToken cancellationToken = default)

Parameters

url string
autoReconnect bool
cancellationToken CancellationToken

Returns

Task<WebSocketConnection>

DisconnectAsync(string, CancellationToken)

public Task DisconnectAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string
cancellationToken CancellationToken

Returns

Task

GetTag(string, string)

public string? GetTag(string id, string key)

Parameters

id string
key string

Returns

string

GetTags(string)

public IReadOnlyDictionary<string, string> GetTags(string id)

Parameters

id string

Returns

IReadOnlyDictionary<string, string>

ListConnectionsAsync(CancellationToken)

public Task<IEnumerable<WebSocketConnection>> ListConnectionsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<IEnumerable<WebSocketConnection>>

ReclaimAsync(string, CancellationToken)

Takes ownership of a connection last known to be owned by another, now-unreachable instance. Unlike a fresh ConnectAsync(string, bool, CancellationToken), the connection ID and its persisted metadata (URL, auto-reconnect, topic, tags) are preserved. If auto-reconnect is set, attempts to open a fresh socket for it immediately -- the old owner's socket object lives in that process's memory, unreachable from here, so this instance genuinely has no live connection until one is (re)established. Returns false if no persisted record exists for id.

public Task<bool> ReclaimAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string
cancellationToken CancellationToken

Returns

Task<bool>

SendAsync(string, byte[], int, string, CancellationToken)

public Task<byte[]> SendAsync(string id, byte[] message, int timeoutMs, string contentType, CancellationToken cancellationToken = default)

Parameters

id string
message byte[]
timeoutMs int
contentType string
cancellationToken CancellationToken

Returns

Task<byte[]>

SendRawAsync(string, byte[], string, CancellationToken)

public Task SendRawAsync(string id, byte[] message, string contentType, CancellationToken cancellationToken = default)

Parameters

id string
message byte[]
contentType string
cancellationToken CancellationToken

Returns

Task

SetTag(string, string, string)

public void SetTag(string id, string key, string value)

Parameters

id string
key string
value string

SetTags(string, IDictionary<string, string>)

public void SetTags(string id, IDictionary<string, string> tags)

Parameters

id string
tags IDictionary<string, string>

StartPublishAsync(string, string, CancellationToken)

public Task StartPublishAsync(string id, string topic, CancellationToken cancellationToken = default)

Parameters

id string
topic string
cancellationToken CancellationToken

Returns

Task

StopPublishAsync(string, CancellationToken)

public Task StopPublishAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string
cancellationToken CancellationToken

Returns

Task