managedcode-orleans-signalr
Integrate ManagedCode.Orleans.SignalR for grain-driven SignalR delivery, connection and group routing, offline user queues, and restart-safe state. USE FOR: Orleans backplane setup, grain-to-hub publishing, reconnect, heartbeat, and client-invocation failures. DO NOT USE FOR: ordinary SignalR without Orleans or unrelated persistence. INVOKES: inspect configuration, implement the integration, and validate connected-client delivery.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 515
- Forks
- 41
01 前言 Front Matter
- name
- managedcode-orleans-signalr
- description
- Integrate ManagedCode.Orleans.SignalR for grain-driven SignalR delivery, connection and group routing, offline user queues, and restart-safe state. USE FOR: Orleans backplane setup, grain-to-hub publishing, reconnect, heartbeat, and client-invocation failures. DO NOT USE FOR: ordinary SignalR without Orleans or unrelated persistence. INVOKES: inspect configuration, implement the integration, and validate connected-client delivery.
- compatibility
- Requires a .NET application with compatible Orleans and ASP.NET Core SignalR packages; use aligned ManagedCode.Orleans.SignalR Client and Server versions.
02 资源文件 1
- 参考文档manifest.json158 B
03 SKILL.md 正文
ManagedCode.Orleans.SignalR
Trigger On
- configuring an Orleans SignalR backplane or sending messages from grains
- diagnosing connection, group, or user routing across hosts
- upgrading offline delivery, heartbeat persistence, or client invocation handling
Install
For a host that runs both the silo and SignalR endpoint:
dotnet add package ManagedCode.Orleans.SignalR.Server --version 10.3.0
dotnet add package ManagedCode.Orleans.SignalR.Client --version 10.3.0
For separate hosts, put Server on the silo and Client on the ASP.NET Core endpoint. Core supplies shared contracts transitively. Keep versions and partition options aligned across participants; preserve central package management when present.
Configure the Backplane
A combined local development host can use the memory provider:
using ManagedCode.Orleans.SignalR.Server.Extensions;
using Microsoft.AspNetCore.SignalR;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseOrleans(silo =>
{
silo.UseLocalhostClustering();
silo.ConfigureOrleansSignalR();
silo.AddOrleansSignalRInMemoryStorage();
});
builder.Services.AddSignalR().AddOrleans(options =>
{
options.ConnectionPartitionCount = 4;
options.GroupPartitionCount = 4;
options.KeepMessageInterval = TimeSpan.FromMinutes(5);
options.MaxQueuedMessagesPerUser = 100;
});
var app = builder.Build();
app.MapHub<UpdatesHub>("/updates");
app.Run();
public sealed class UpdatesHub : Hub { }
Import only Server.Extensions for this combined host; a separate client-only endpoint uses Client.Extensions. Importing both makes AddOrleans ambiguous. Use authenticated hub endpoints and the application's existing cluster discovery in deployed environments. The memory provider does not survive silo restarts. When offline delivery must survive restarts, register a durable Orleans grain-storage provider under OrleansSignalROptions.OrleansSignalRStorage instead of the memory helper. Connection metadata, queued messages, heartbeat registrations, and invocation state use this named store.
Send and Receive Updates
Inject IHubContext<UpdatesHub> into the grain or application service that owns the event:
using Microsoft.AspNetCore.SignalR;
public sealed class UpdatePublisher(IHubContext<UpdatesHub> hub)
{
public Task NotifyUserAsync(string userId, string eventId, string text) =>
hub.Clients.User(userId).SendAsync("Updated", eventId, text);
public Task NotifyGroupAsync(string group, string eventId, string text) =>
hub.Clients.Group(group).SendAsync("Updated", eventId, text);
}
Register a receiver before starting the connection. This example uses the application's @microsoft/signalr client:
import { HubConnectionBuilder } from '@microsoft/signalr';
const connection = new HubConnectionBuilder()
.withUrl('/updates')
.withAutomaticReconnect()
.build();
connection.on('Updated', (eventId, text) => {
renderUpdate(eventId, text); // Application-owned rendering and deduplication.
});
await connection.start();
Derive userId and permitted group membership from authenticated application identity. Never treat a client-supplied user or group name as authorization. Keep domain state in the owning grain; the backplane transports notifications about that state.
Delivery and Upgrade Boundaries
10.3.0persists queued offline user messages with delivery IDs and expiry, removing them after acknowledgement. Successful dispatch or queue storage is not proof that the browser applied the update; use application event IDs and idempotent handlers when replay matters.KeepMessageIntervalbounds offline retention.MaxQueuedMessagesPerUserdefaults to 100 and discards oldest entries when exceeded. Test expiry and overflow explicitly; offline queues are not an unlimited event log.KeepEachConnectionAliverenews a bounded heartbeat lease. Disabling it relies on ordinary observer/activation lifecycle; it does not make disconnected observers immortal. Test clean disconnect and abrupt host loss independently.- Observer failure thresholds, grace-period buffering, and circuit-breaker options affect retries and cleanup. Set them from measured reconnect behavior and watch drop/failure metrics.
- Internal persisted
HubMessageStatechanged from a dictionary to aQueuedHubMessagelist, andISignalRInvocationGrain.WaitForCompletionnow returns a cancellation-awareIAsyncEnumerable<CqrsStreamChunk<InvocationProgress, CompletionMessage>>. Applications using these lower-level contracts must validate serialization and mixed-version compatibility before rolling upgrades. - A storage write failure must remain observable. Test retry and reactivation with the actual configured serializer and storage provider; an in-memory-only test does not prove durable recovery.
flowchart LR
G[Grain or service] --> H[IHubContext]
H --> R[Orleans connection, group, or user routing]
R --> L[Live observer dispatch]
R --> Q[Offline user queue in named grain storage]
Q --> P[Reconnect and replay]
P --> A[Acknowledge delivery ID]
A --> D[Remove queued message]
L --> C[SignalR client]
P --> C
Workflow
- Choose combined or separate silo/endpoint hosts and align packages, clustering, partition options, and named storage.
- Configure authenticated connection, user, and group targeting.
- Keep publishing at an explicit domain-event boundary and decide whether bounded offline retention is sufficient.
- Exercise live delivery, reconnect replay, queue limits, heartbeat cleanup, and interrupted client invocations.
- Before upgrades, validate prior persisted payloads with the production serializer and choose an explicit compatibility or maintenance-window strategy.
Deliver
- configured backplane and named storage with a stated durability boundary
- a working publisher and client receiver
- evidence for the required live, offline, restart, and failure behavior
Validate
dotnet restoreanddotnet buildresolve the aligned package set- a real connected client receives a grain-originated message on another host
- user/group isolation, reconnect, queue expiry/overflow, and heartbeat cleanup work
- restart tests preserve queued messages only when durable storage is configured
- cancellation and missing-client completion terminate predictably
- tests keep unrelated cases parallel; isolate destructive restart tests by their owned cluster
Sources
04 同仓库更多 Skills
xtwitter-scraper
Use XTwitterScraper when a .NET application needs typed access to Xquik's X automation REST API for tweet search, user lookup, posting workflows, extraction jobs, monitors, webhooks, or giveaway draws. USE FOR: integrating the XTwitterScraper NuGet package; reviewing Xquik API client usage; modeling API-key configuration, pagination, binary exports, raw responses, retries, and webhook/event flows in .NET. DO NOT USE FOR: unrelated stacks; direct browser automation; generic social-media strategy; or code that does not call Xquik. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.
sep
Use Sep for high-performance separated-value parsing and writing in .NET, including delimiter inference, explicit parser/writer options, and low-allocation row/column workflows. USE FOR: delimited data needs are performance-sensitive and allocation-aware; project needs explicit control over separator inference, escaping, trimming, and header behavior;. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.
webgpu-threejs-tsl
Comprehensive guide for developing WebGPU-enabled Three.js applications using TSL (Three.js Shading Language). Covers WebGPU renderer setup, TSL syntax and node materials, compute shaders, post-processing effects, and WGSL integration. Use this skill when working with Three.js WebGPU, TSL shaders, node materials, or GPU compute in Three.js.
roslynk
Use Roslynk for semantic inspection and edits of *.cs, *.razor and *.cshtml solution files.
system-text-json-net11
Imperative guidance for the System.Text.Json APIs added in .NET 11: the built-in `JsonNamingPolicy.PascalCase` naming policy, and the strongly-typed generic `JsonSerializerOptions.GetTypeInfo` and `JsonSerializerOptions.TryGetTypeInfo` metadata accessors (generic overloads that return a typed `JsonTypeInfo`). USE ONLY when the user is targeting net11.0 or later and needs PascalCase JSON property or dictionary-key names without writing a custom naming policy, a strongly-typed generic `JsonTypeInfo` instead of the non-generic `JsonTypeInfo`, or a no-throw way to probe whether a type's serialization metadata is resolved. DO NOT USE when the target is earlier than net11.0, the requested behavior uses an established pre-net11 naming policy, or the user explicitly selected another JSON library.
process-api-net11
Provides guidance on the new System.Diagnostics.Process APIs introduced in .NET 11: Process.Run, Process.RunAndCaptureText, Process.StartAndForget, Process.ReadAllText/Bytes/Lines, KillOnParentExit, InheritedHandles, and StartDetached. USE FOR: starting, orchestrating, or capturing output from external processes in applications targeting net11.0 or later. DO NOT USE FOR: applications targeting .NET 10 or earlier, or basic pre-.NET 11 Process.Start usage without new APIs.