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
connectionStoreIWebSocketConnectionStorewebSocketClientIWebSocketClientWrapperdaprPublisherIDaprPublisherurlValidatorIWebSocketUrlValidatorloggerILogger<WebSocketService>
Methods
ConnectAsync(string, string, bool, CancellationToken)
Opens a new WebSocket connection under id -- minted
by the caller (WebSocketManagerGrpcService.Connect), which
activates the owning WebSocketConnectionActor for it before
this ever runs, rather than generated in here.
public Task<WebSocketConnection> ConnectAsync(string id, string url, bool autoReconnect, CancellationToken cancellationToken = default)
Parameters
idstringurlstringautoReconnectboolcancellationTokenCancellationToken
Returns
DisconnectAsync(string, CancellationToken)
public Task DisconnectAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringcancellationTokenCancellationToken
Returns
EnsureLocalAsync(string, CancellationToken)
Self-heals a connection whose actor was just activated on this instance without ever opening its socket here -- a genuine failover/rebalance of an already-connected id (the previous owner gone, or this actor freshly reactivated after an idle deactivation), not a fresh ConnectAsync(string, string, bool, CancellationToken) (which registers the connection locally itself, so this is always a no-op right after one of those). Reconnects immediately if auto-reconnect was set. A no-op if the connection is already local, or if there's no persisted record for it at all.
public Task EnsureLocalAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringcancellationTokenCancellationToken
Returns
GetTag(string, string)
public string? GetTag(string id, string key)
Parameters
Returns
GetTags(string)
public IReadOnlyDictionary<string, string> GetTags(string id)
Parameters
idstring
Returns
ListConnectionsAsync(CancellationToken)
public Task<IEnumerable<WebSocketConnection>> ListConnectionsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
SendAsync(string, byte[], int, string, CancellationToken)
public Task<byte[]> SendAsync(string id, byte[] message, int timeoutMs, string contentType, CancellationToken cancellationToken = default)
Parameters
idstringmessagebyte[]timeoutMsintcontentTypestringcancellationTokenCancellationToken
Returns
SendRawAsync(string, byte[], string, CancellationToken)
public Task SendRawAsync(string id, byte[] message, string contentType, CancellationToken cancellationToken = default)
Parameters
idstringmessagebyte[]contentTypestringcancellationTokenCancellationToken
Returns
SetTagAsync(string, string, string, CancellationToken)
Persists the tag via UpdateConnectionAsync(WebSocketConnection, CancellationToken)
so it survives to List()'s cross-instance view (that of a
connection owned by another instance comes from the persisted store,
not this instance's own in-memory copy) -- unlike the pre-0.4.2
version, which only ever mutated the in-memory Tags
dictionary. GetTag(string, string)/GetTags(string) are unaffected
by this either way: both RPCs already route through the actor to the
true owner, which always has the live in-memory value regardless of
persistence.
public Task SetTagAsync(string id, string key, string value, CancellationToken cancellationToken = default)
Parameters
idstringkeystringvaluestringcancellationTokenCancellationToken
Returns
SetTagsAsync(string, IDictionary<string, string>, CancellationToken)
See SetTagAsync(string, string, string, CancellationToken) -- same persistence, plural.
public Task SetTagsAsync(string id, IDictionary<string, string> tags, CancellationToken cancellationToken = default)
Parameters
idstringtagsIDictionary<string, string>cancellationTokenCancellationToken
Returns
StartPublishAsync(string, string, CancellationToken)
public Task StartPublishAsync(string id, string topic, CancellationToken cancellationToken = default)
Parameters
idstringtopicstringcancellationTokenCancellationToken
Returns
StopPublishAsync(string, CancellationToken)
public Task StopPublishAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringcancellationTokenCancellationToken