Agent Skillsmanagedcode/dotnet-skills › managedcode-orleans-signalr

managedcode-orleans-signalr

GitHub

集成 ManagedCode.Orleans.SignalR,实现 Orleans Grain 驱动的信号传输、连接管理、离线队列及状态持久化。提供配置指南、消息发送与接收示例,确保实时分布式应用中的可靠通信。

catalog/Libraries/ManagedCode-Orleans-SignalR/skills/managedcode-orleans-signalr/SKILL.md managedcode/dotnet-skills

触发场景

配置 Orleans SignalR 后端总线 从 Grain 发送消息 诊断跨主机连接或路由问题 升级离线投递或心跳机制

安装

npx skills add managedcode/dotnet-skills --skill managedcode-orleans-signalr -g -y
更多选项

非标准路径

npx skills add https://github.com/managedcode/dotnet-skills/tree/main/catalog/Libraries/ManagedCode-Orleans-SignalR/skills/managedcode-orleans-signalr -g -y

不安装直接使用

npx skills use managedcode/dotnet-skills@managedcode-orleans-signalr

指定 Agent (Claude Code)

npx skills add managedcode/dotnet-skills --skill managedcode-orleans-signalr -a claude-code -g -y

安装 repo 全部 skill

npx skills add managedcode/dotnet-skills --all -g -y

预览 repo 内 skill

npx skills add managedcode/dotnet-skills --list

SKILL.md

Frontmatter
{
    "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."
}

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.0 persists 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.
  • KeepMessageInterval bounds offline retention. MaxQueuedMessagesPerUser defaults to 100 and discards oldest entries when exceeded. Test expiry and overflow explicitly; offline queues are not an unlimited event log.
  • KeepEachConnectionAlive renews 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 HubMessageState changed from a dictionary to a QueuedHubMessage list, and ISignalRInvocationGrain.WaitForCompletion now returns a cancellation-aware IAsyncEnumerable<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

  1. Choose combined or separate silo/endpoint hosts and align packages, clustering, partition options, and named storage.
  2. Configure authenticated connection, user, and group targeting.
  3. Keep publishing at an explicit domain-event boundary and decide whether bounded offline retention is sufficient.
  4. Exercise live delivery, reconnect replay, queue limits, heartbeat cleanup, and interrupted client invocations.
  5. 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 restore and dotnet build resolve 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

版本历史

  • d26ba3c 当前 2026-09-09 06:42

    更新触发场景,细化安装与配置说明,强调内存与持久化存储的区别,补充代码示例。

  • 7ab7f03 2026-07-25 05:23

同 Skill 集合

catalog/Frameworks/gRPC/skills/grpc/SKILL.md
catalog/Frameworks/Official-Astro/skills/astro-developer/SKILL.md
catalog/Frameworks/Official-DotNet-ASPNetCore/skills/configuring-opentelemetry-dotnet/SKILL.md
catalog/Frameworks/Official-DotNet-ASPNetCore/skills/dotnet-webapi/SKILL.md
catalog/Frameworks/Official-DotNet-ASPNetCore/skills/minimal-api-file-upload/SKILL.md
catalog/Frameworks/Orleans/skills/orleans/SKILL.md
catalog/Frameworks/ThreeJS-WebGPU-TSL/skills/webgpu-threejs-tsl/SKILL.md
catalog/Libraries/Official-DotNet-Data/skills/optimizing-ef-core-queries/SKILL.md
catalog/Platform/Official-DotNet-Advanced/skills/csharp-scripts/SKILL.md
catalog/Platform/Official-DotNet-Advanced/skills/nuget-trusted-publishing/SKILL.md
catalog/Platform/Official-DotNet-Advanced/skills/vectorization/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/create-blazor-project/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/fetch-and-send-data/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/support-prerendering/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/use-js-interop/SKILL.md
catalog/Platform/Official-DotNet-Experimental/skills/exp-mock-usage-analysis/SKILL.md
catalog/Platform/Official-DotNet-Experimental/skills/exp-simd-vectorization/SKILL.md
catalog/Platform/Official-DotNet-Upgrade/skills/dotnet-aot-compat/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/code-testing-extensions/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/crap-score/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/filter-syntax/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/find-untested-sources/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/test-tagging/SKILL.md
catalog/Testing/Playwright/skills/playwright-visual-testing/SKILL.md
catalog/Testing/TUnit/skills/tunit/SKILL.md
catalog/Testing/xUnit/skills/xunit/SKILL.md
catalog/Tools/Code-Analysis/skills/code-analysis/SKILL.md
catalog/Tools/Format/skills/format/SKILL.md
catalog/Tools/HTMLHint/skills/htmlhint/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/analyzing-dotnet-performance/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/clr-activation-debugging/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/dotnet-trace-collect/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/dump-collect/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/binlog-failure-analysis/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/copy-to-output-directory/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/msbuild-server/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/resolve-project-references/SKILL.md
catalog/Tools/ReportGenerator/skills/reportgenerator/SKILL.md
catalog/Tools/ReSharper-CLT/skills/resharper-clt/SKILL.md
catalog/Tools/Roslynator/skills/roslynator/SKILL.md
catalog/Tools/Stylelint/skills/stylelint/SKILL.md
external-sources/upstreams/webgpu-claude-skill/skills/webgpu-threejs-tsl/SKILL.md
catalog/Frameworks/ASP.NET-Core/skills/aspnet-core/SKILL.md
catalog/Frameworks/Aspire/skills/aspire/SKILL.md
catalog/Frameworks/Azure-Functions/skills/azure-functions/SKILL.md
catalog/Frameworks/Blazor/skills/blazor/SKILL.md
catalog/Frameworks/Entity-Framework-6/skills/entity-framework6/SKILL.md
catalog/Frameworks/Entity-Framework-Core/skills/entity-framework-core/SKILL.md
catalog/Frameworks/MAUI/skills/maui/SKILL.md

元信息

文件数
0
版本
d26ba3c
Hash
202b7fa7
收录时间
2026-07-25 05:23

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-09 21:27
浙ICP备14020137号-1 $访客地图$