Skip to content

API Overview ​

This page lists the public API surface of SignalARRR across all packages.

Server API (Cocoar.SignalARRR.Server) ​

Registration ​

csharp
// IServiceCollection extension
services.AddSignalARRR(options => options
    .AddServerMethodsFrom(assembly));

// Requires the Cocoar.SignalARRR.Server.Backplane.Redis package
services.AddSignalARRRRedisBackplane(options => options
    .WithConnectionString("localhost:6379,abortConnect=false")
    .WithChannelPrefix("my-app")
    .WithNodeId("node-1"));

// Requires the Cocoar.SignalARRR.Server.Backplane.Postgres package
services.AddSignalARRRPostgresBackplane(options => options
    .WithConnectionString("Host=db;Database=app;Username=app;Password=...")
    .WithSchema("signalarrr")
    .WithNodeId("node-1"));

// An observable whose events reach subscribers on every node (cluster subjects)
services.AddSignalARRRClusterSubject<OrderChanged>("orders");

// IEndpointRouteBuilder extension
app.MapSignalARRRHub<THub>(path);
app.MapSignalARRRHub<THub>(path, configureOptions);

HARRR (Hub base class) ​

MemberTypeDescription
ServiceProviderIServiceProviderDI container
LoggerILogger?Logger instance
ClientContextClientContextCurrent client context
OnConnectedAsync()TaskClient connected (registers in ClientManager)
OnDisconnectedAsync(Exception?)TaskClient disconnected (unregisters)

Hub methods (wire protocol — called by clients internally):

MethodDescription
InvokeMessage(ClientRequestMessage)Fire-and-forget
InvokeMessageResult(ClientRequestMessage)Returns result
SendMessage(ClientRequestMessage)Fire-and-forget (async void)
StreamMessage(ClientRequestMessage, CancellationToken)Server-to-client stream
StreamItemToServer(Guid, object)Client-to-server stream item
StreamCompleteToServer(Guid, string?)Client-to-server stream completion

ServerMethods / ServerMethods<T> ​

PropertyTypeDescription
ClientContextClientContextCurrent client context
ContextHubCallerContextSignalR caller context
ClientsIHubCallerClientsClient connections
GroupsIGroupManagerGroup management
LoggerILoggerLogger

ClientContext ​

PropertyTypeDescription
IdstringConnection ID
HARRRTypeTypeHub type
RemoteIpIPAddress?Client IP
UserClaimsPrincipalAuthenticated user
UserValidUntilDateTimeToken expiration
ConnectedAtDateTimeConnection time
ReconnectedAtList<DateTime>Reconnection history
AttributesClientAttributesCustom key-value storage
ConnectedToUriHub URL
MethodDescription
GetTypedMethods<T>()Get typed proxy to call this client
TryAuthenticate(MethodInfo)Validate token, challenge if expired

ClientManager ​

MethodDescription
WithHub<THub>()Select hub — primary entry point for queries. Returns IClientQuery
GetClientById(string)Get client by connection ID
GetAllClients()All connected clients across all hubs — this node only
GetAllClients(predicate)Filter those clients

IClientQuery ​

Returned by WithHub<THub>(). Describes a target set; with a backplane enabled, the filters and the send/invoke methods resolve across the whole cluster.

MethodDescription
WithGroup(string)Narrow to a SignalR group — cluster-wide
WithUser(string)Narrow to a user's connections — cluster-wide
WithAttribute(string, string?)Narrow by connection attribute — cluster-wide
WithLocalFilter(predicate)Narrow by any predicate — confines the query to this node
SendAsync<T>(action)Fire-and-forget to the whole target set
InvokeAllAsync<T, TResult>(func)Invoke each client, collect all results
InvokeOneAsync<T, TResult>(func)Invoke until the first success
LocalClients()The matching ClientContexts owned by this node
AddToGroupAsync(connectionId, groupName)Add client to SignalR group (tracked in ClientContext.Groups)
RemoveFromGroupAsync(connectionId, groupName)Remove client from group
GetConnectionsAsync<THub>()Connection snapshots for the selected hub
GetConnectionsByUserAsync<THub>(string)Connection snapshots for one user
GetConnectionsInGroupAsync<THub>(string)Connection snapshots for one group
GetConnectionsByAttributeAsync<THub>(string, string?)Connection snapshots matching an attribute
GetOnlineUsersAsync<THub>()User presence snapshots for the hub
IsUserOnlineAsync<THub>(string)Check whether a user is online

SignalARRRRedisBackplaneOptionsBuilder ​

MethodDescription
WithConnectionString(string)Configure the Redis-compatible backend connection
WithChannelPrefix(string)Prefix all backplane keys/channels for app isolation
WithNodeId(string)Set a stable logical node identifier
WithInvokeTimeout(TimeSpan)Timeout for cross-node invoke aggregation
WithHeartbeatInterval(TimeSpan)Heartbeat interval for dead-node detection
WithNodeTimeout(TimeSpan)Time after which a node is considered stale

SignalARRRPostgresBackplaneOptionsBuilder ​

MethodDescription
WithConnectionString(string)Npgsql connection string of the PostgreSQL primary
WithSchema(string)Schema for the backplane's tables; also names the notification channels, so it isolates applications sharing a database. Lowercase identifier, max 50 chars. Default signalarrr
WithAutoCreateSchema(bool)Create schema and tables on startup (default true); off, the tables must exist — see SignalARRRPostgresBackplaneSchema.GetCreateScript
WithCatchUp(bool)Replay messages missed while the subscription was down (default true); off, they are lost, as with Redis
WithMessageRetention(TimeSpan)How long messages stay replayable, and the longest outage catch-up covers in full. Default 5 minutes
WithNodeId(string)Set a stable logical node identifier
WithInvokeTimeout(TimeSpan)Timeout for cross-node invoke aggregation
WithHeartbeatInterval(TimeSpan)Heartbeat interval for dead-node detection
WithNodeTimeout(TimeSpan)Time after which a node is considered stale; must exceed the heartbeat interval

IClusterSubject<T> ​

Registered with AddSignalARRRClusterSubject<T>(name, configure?); resolved by T. See Cluster-aware observables.

MemberDescription
NameThe cluster-wide name events are matched by
OnNext(T)Raise for local subscribers now and for the other nodes fire-and-forget
PublishAsync(T, CancellationToken)Raise and await the hand-off to the backplane
Subscribe(IObserver<T>)It is an IObservable<T>: use it with Rx operators or return it from a hub stream method

ClusterSubjectOptions.SerializerOptions sets the JsonSerializerOptions events cross the wire with (default: web defaults).

SignalARRRPostgresBackplaneSchema ​

MemberDescription
GetCreateScript(string schema = "signalarrr")The idempotent DDL (IF NOT EXISTS) for the backplane's schema, tables and indexes, for operators who apply it through migrations

Presence models ​

TypePurpose
SignalARRRConnectionSnapshotConnection ID, node ID, user ID, groups, and attributes
SignalARRRUserPresenceSnapshotUser ID plus aggregated connection IDs and node IDs

Client API (Cocoar.SignalARRR.Client) ​

HARRRConnection ​

Static methodDescription
Create(Action<HubConnectionBuilder>, options?)Create from builder
Create(HubConnection, options?)Wrap existing connection
MethodDescription
GetTypedMethods<T>()Get typed proxy for a contract interface
InvokeCoreAsync<T>(message, ct)Call server, await typed result
SendCoreAsync(message, ct)Fire-and-forget
StreamAsyncCore<T>(message, ct)Server-to-client stream
RegisterInterface<TInterface, TClass>(...)Register a server-to-client contract handler (instance, factory or type)
StartAsync(ct)Connect
StopAsync(ct)Disconnect
DisposeAsync()Dispose
AsSignalRHubConnection()Access raw HubConnection
PropertyTypeDescription
ConnectionIdstring?Connection ID
StateHubConnectionStateConnection state
ServerTimeoutTimeSpanServer timeout
KeepAliveIntervalTimeSpanKeepalive interval
HandshakeTimeoutTimeSpanHandshake timeout
EventDescription
ClosedFires when connection closes
ReconnectingFires when reconnecting
ReconnectedFires when reconnected

TypeScript API (@cocoar/signalarrr) ​

HARRRConnection ​

ts
class HARRRConnection {
    static create(builderOrConnection, options?): HARRRConnection

    invoke<T>(methodName: string, ...args: unknown[]): Promise<T>
    send(methodName: string, ...args: unknown[]): Promise<void>
    stream<T>(methodName: string, ...args: unknown[]): IStreamResult<T>

    onServerMethod(methodName: string, handler: (...args) => unknown): this

    start(): Promise<void>
    stop(): Promise<void>
    asSignalRHubConnection(): signalR.HubConnection

    onClose(callback: (error?) => void): void
    onReconnecting(callback: (error?) => void): void
    onReconnected(callback: (connectionId?) => void): void

    connectionId: string | null
    state: HubConnectionState
    baseUrl: string
    serverTimeoutInMilliseconds: number
    keepAliveIntervalInMilliseconds: number
}

Exported types ​

ts
export { HARRRConnection } from './harrr-connection.js'
export { HARRRConnectionOptions } from './harrr-connection-options.js'
export type { ClientRequestMessage } from './models/client-request-message.js'
export type { ServerRequestMessage } from './models/server-request-message.js'
export type { CancellationTokenReference } from './models/cancellation-token-reference.js'

Common types (Cocoar.SignalARRR.Common) ​

ClientRequestMessage ​

PropertyTypeDescription
MethodstringMethod name (ClassName.MethodName)
Argumentsobject[]Method arguments
Authorizationstring?Bearer token
GenericArgumentsstring[]Generic type arguments

ServerRequestMessage ​

PropertyTypeDescription
IdGuidCorrelation ID for reply
MethodstringMethod name
Argumentsobject[]Method arguments
GenericArgumentsstring[]Generic type arguments
CancellationGuidGuid?Cancellation correlation ID
StreamIdGuid?Stream correlation ID

Attributes ​

AttributeDescription
[SignalARRRContract]Marks an interface for proxy generation
[MessageName(string)]Override the default method name

Next steps ​

Released under the Apache-2.0 License.