grpc

GitHub

用于在.NET中构建或审查gRPC服务与客户端,涵盖protobuf契约、流式调用、拦截器及性能优化。适用于后端RPC集成,排除浏览器API和SignalR场景。

catalog/Frameworks/gRPC/skills/grpc/SKILL.md managedcode/dotnet-skills

Trigger Scenarios

构建后端到后端的RPC服务或客户端 添加protobuf契约或流式调用 决定使用gRPC还是HTTP/SignalR 优化gRPC性能与连接复用

Install

npx skills add managedcode/dotnet-skills --skill grpc -g -y
More Options

Non-standard path

npx skills add https://github.com/managedcode/dotnet-skills/tree/main/catalog/Frameworks/gRPC/skills/grpc -g -y

Use without installing

npx skills use managedcode/dotnet-skills@grpc

指定 Agent (Claude Code)

npx skills add managedcode/dotnet-skills --skill grpc -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": "grpc",
    "description": "Build or review gRPC services and clients in .NET. USE FOR: ASP.NET Core gRPC, protobuf contracts, unary or streaming RPC, gRPC client factory, interceptors, deadlines, cancellation, channel reuse, backend service integration. DO NOT USE FOR: broad browser-facing APIs without gRPC-Web tradeoff review, SignalR realtime hubs, plain REST APIs. INVOKES: dotnet build\/test and focused service or client smoke checks when code changes.",
    "compatibility": "Requires ASP.NET Core gRPC or gRPC client projects."
}

gRPC for .NET

Trigger On

  • building backend-to-backend RPC services or clients
  • adding protobuf contracts, streaming calls, or interceptors
  • deciding between gRPC, HTTP APIs, and SignalR
  • optimizing gRPC performance, deadlines, cancellation, or connection reuse
  • integrating service-to-service communication in microservices

Do Not Use For

  • public browser-first APIs unless gRPC-Web limitations are explicitly acceptable
  • SignalR hub design, realtime UI fan-out, or websocket-style client collaboration
  • generic ASP.NET Core minimal APIs or REST controllers with no protobuf/RPC requirement
  • non-.NET gRPC work unless the user asks for cross-stack contract guidance

Load References

  • references/patterns.md for proto design, streaming implementations, interceptors, health checks, load balancing, and client factory setup.
  • references/anti-patterns.md for common channel, deadline, streaming, message-size, and exception-handling mistakes.

Workflow

  1. Validate the architecture fit before touching code.
    • prefer gRPC for backend RPC, strong contracts, low-latency calls, or streaming
    • prefer REST or minimal APIs for broad browser compatibility and loosely coupled public APIs
    • prefer SignalR for browser/client realtime fan-out and UI collaboration
  2. Treat .proto files as the source of truth.
    • keep package names, csharp_namespace, service names, and versioning deliberate
    • reserve removed field numbers and avoid reusing tags
    • use wrapper types or explicit messages when optionality matters
  3. Choose the RPC shape from the interaction model.
    • unary for request/response
    • server streaming for large or progressive result sets
    • client streaming for uploads or batches
    • bidirectional streaming for coordinated two-way flows
  4. Wire server and client behavior together.
    • register services with AddGrpc
    • use AddGrpcClient or long-lived GrpcChannel reuse
    • set deadlines and propagate cancellation
    • convert domain failures to appropriate RpcException status codes
  5. Add observability and resilience where the boundary justifies it.
    • logging or exception interceptors
    • OpenTelemetry traces and status-code metrics
    • retry policy only for safe idempotent calls
  6. Validate with the repo's normal build and tests, plus a focused smoke call when runnable.

Current Upstream Notes

  • dotnet/aspnetcore v10.0.11 is servicing and does not change the gRPC programming model. Keep guidance focused on proto compatibility, streaming shape, deadlines, cancellation, channel reuse, and smoke calls.
  • The August 2026 ASP.NET Core overview still treats gRPC as a contract-first RPC option. After package servicing updates, regenerate protobuf outputs only when inputs or generator packages actually changed; do not churn generated files as a proxy for validation.
flowchart LR
  A["RPC requirement"] --> B["proto contract"]
  B --> C["server implementation"]
  B --> D["client factory or channel"]
  C --> E["deadlines / cancellation / status codes"]
  D --> E
  E --> F["build, tests, smoke call"]

Examples

Use client factory for normal app integration:

builder.Services.AddGrpcClient<Greeter.GreeterClient>(options =>
{
    options.Address = new Uri("https://localhost:5001");
});

Always set a deadline and pass cancellation:

var response = await client.SayHelloAsync(
    new HelloRequest { Name = name },
    deadline: DateTime.UtcNow.AddSeconds(5),
    cancellationToken: cancellationToken);

For streaming, check cancellation inside the read/write loop and keep message sizes bounded. Load references/patterns.md before writing detailed streaming code.

Anti-Patterns

  • creating a new GrpcChannel per call
  • omitting deadlines and relying only on client-side cancellation
  • ignoring ServerCallContext.CancellationToken in streaming handlers
  • sending large single messages instead of chunking or streaming
  • using gRPC as the default public browser API
  • swallowing exceptions inside interceptors
  • retrying non-idempotent calls without explicit policy

Deliver

  • stable protobuf contracts and generated-code ownership
  • service and client code that match the RPC shape
  • explicit deadline, cancellation, retry, and status-code behavior
  • tests or smoke checks for serialization and call behavior
  • documentation of browser, transport, or deployment constraints when relevant

Validate

  • dotnet build succeeds after contract or generated-code changes
  • tests or smoke checks exercise at least one server/client call
  • streaming methods respect cancellation and bounded message sizes
  • channels are reused through client factory or a long-lived channel
  • status-code handling is intentional and observable
  • browser constraints are documented if gRPC-Web is involved

Version History

  • 0559476 Current 2026-08-19 23:32

    更新上游ASP.NET Core版本说明,强调仅在输入或生成包变更时重新生成protobuf文件,避免无效变更。

  • 7ab7f03 2026-07-25 05:23

Same Skill Collection

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-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-Test-Migration/skills/migrate-xunit-to-mstest/SKILL.md
catalog/Platform/Official-DotNet-Test-Migration/skills/migrate-xunit-to-xunit-v3/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/filter-syntax/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/find-untested-sources/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/platform-detection/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/scaffold-dotnet-test-project/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/test-gap-analysis/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/testability-obstacle/SKILL.md
catalog/Testing/Playwright/skills/playwright-visual-testing/SKILL.md
catalog/Testing/xUnit/skills/xunit/SKILL.md
catalog/Tools/Code-Analysis/skills/code-analysis/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

Metadata

Files
0
Version
0559476
Hash
c99f002e
Indexed
2026-07-25 05:23

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-20 06:37
浙ICP备14020137号-1 $mapa de visitantes$