Community编程与开发github.com

akka-net-aspire-配置

配合 .NET Aspire 配置 Akka.NET,用于本地开发和生产部署。涵盖 Actor 系统设置、集群、持久化、Akka.Management 集成以及 Aspire 编排模式。

akka-net-aspire-配置 是什么?

此技能指导开发者使用 .NET Aspire 配置和部署 Akka.NET 应用,支持从本地开发到生产部署的全流程。它聚焦于将 Akka.NET 的集群、持久化和管理功能无缝集成到 Aspire 编排环境中,利用 Microsoft.Extensions.Configuration 实现强类型配置绑定,并通过 Akka.Hosting 简化依赖注入。技能详细解释了 Actor 系统设置、集群引导(Cluster Bootstrap)、服务发现(支持 Kubernetes、Azure 表格存储或静态配置)、TLS 安全配置以及 SQL Server 持久化。此外,它还涵盖了健康检查、启动验证和 Petabridge.Cmd 管理工具。该技能适用于使用 Akka.NET 构建分布式、可扩展的微服务或 Actor 系统,并希望利用 Aspire 简化本地开发和云部署(如 Kubernetes)的 .NET 开发者。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Aaronontheweb/dotnet-skills/tree/main/skills/akka-aspire-configuration

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

使用 .NET Aspire 配置 Akka.NET

何时使用此技能

适用场景:

  • 使用 .NET Aspire 编排搭建新的 Akka.NET 项目
  • 配置带有集群引导和发现的 Akka.Cluster
  • 集成 SQL Server 的 Akka.Persistence
  • 设置 Akka.Management 进行集群管理
  • 在本地开发中配置多副本 Actor 系统
  • 使用 Aspire 将 Akka.NET 应用部署到 Kubernetes

相关技能

  • akka-net-management - 深入探讨 Akka.Management、集群引导和发现提供程序(Kubernetes、Azure、配置)
  • microsoft-extensions-configuration - 使用 IValidateOptions 模式进行配置验证
  • akka-net-best-practices - 集群/本地模式抽象,用于可测试的 Actor 系统
  • aspire-integration-testing - 使用真实基础设施测试 Aspire 应用

核心原则

  1. 通过 Microsoft.Extensions.Configuration 进行配置 - 使用从 appsettings.json 绑定的强类型设置类(参见 microsoft-extensions-configuration 技能)
  2. 使用 Akka.Hosting 进行 DI 集成 - 使用 Akka.Hosting 库实现与 ASP.NET Core 的无缝集成
  3. 使用 Aspire 进行编排 - 让 Aspire 管理服务依赖、网络和环境配置
  4. 健康检查 - 始终为集群、持久化和就绪状态配置健康检查
  5. 关注点分离 - 将 Actor 定义、配置和 Aspire 编排保持在不同层中
  6. 启动时验证配置 - 使用 IValidateOptions<T> 和 .ValidateOnStart() 在配置错误时快速失败

项目结构

YourSolution/
├── src/
│   ├── YourApp.Actors/              # Actor 定义和业务逻辑
│   │   ├── YourActor.cs
│   │   └── YourApp.Actors.csproj
│   ├── YourApp/                     # ASP.NET Core Web 应用
│   │   ├── Config/
│   │   │   ├── AkkaConfiguration.cs  # Akka 设置扩展方法
│   │   │   └── AkkaSettings.cs       # 配置模型
│   │   ├── Program.cs
│   │   ├── appsettings.json
│   │   └── YourApp.csproj
│   └── YourApp.AppHost/             # Aspire 编排
│       ├── Program.cs
│       ├── AkkaManagementExtensions.cs
│       └── YourApp.AppHost.csproj

所需 NuGet 包

Actor 项目 (YourApp.Actors.csproj)

<ItemGroup>
  <PackageReference Include="Akka.Cluster.Hosting" />
  <PackageReference Include="Akka.Streams" />
</ItemGroup>

Web 应用 (YourApp.csproj)

<ItemGroup>
  <PackageReference Include="Akka.Hosting" />
  <PackageReference Include="Akka.Cluster.Hosting" />
  <PackageReference Include="Akka.Persistence.Sql.Hosting" />
  <PackageReference Include="Akka.Management" />
  <PackageReference Include="Akka.Management.Cluster.Bootstrap" />
  <PackageReference Include="Akka.Discovery.KubernetesApi" />
  <PackageReference Include="Akka.Discovery.Azure" />
  <PackageReference Include="Akka.Discovery.Config.Hosting" />
  <PackageReference Include="Petabridge.Cmd.Host" />
  <PackageReference Include="Petabridge.Cmd.Cluster" />
</ItemGroup>

AppHost 项目 (YourApp.AppHost.csproj)

<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireVersion)" />

<ItemGroup>
  <PackageReference Include="Aspire.Hosting.AppHost" />
  <PackageReference Include="Aspire.Hosting.Azure.Storage" />
  <PackageReference Include="Aspire.Hosting.SqlServer" />
</ItemGroup>

配置模型 (AkkaSettings.cs)

创建强类型配置类:

using System.Net;
using System.Security.Cryptography.X509Certificates;
using Akka.Cluster.Hosting;
using Akka.Remote.Hosting;
using Petabridge.Cmd.Host;

namespace YourApp.Config;

public class AkkaSettings
{
    public string ActorSystemName { get; set; } = "YourSystem";

    public bool LogConfigOnStart { get; set; } = false;

    public RemoteOptions RemoteOptions { get; set; } = new()
    {
        PublicHostName = Dns.GetHostName(),
        HostName = "0.0.0.0",
        Port = 8081
    };

    public ClusterOptions ClusterOptions { get; set; } = new()
    {
        SeedNodes = [$

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

akka-hosting-actor-patterns

Patterns for building entity actors with Akka.Hosting - GenericChildPerEntityParent, message extractors, cluster sharding abstraction, akka-reminders, and ITimeProvider. Supports both local testing and clustered production modes.

akka-net-best-practices

Critical Akka.NET best practices including EventStream vs DistributedPubSub, supervision strategies, error handling, Props vs DependencyResolver, work distribution patterns, and cluster/local mode abstractions for testability.

akka-net-management

Akka.Management for cluster bootstrapping, service discovery (Kubernetes, Azure, Config), health checks, and dynamic cluster formation without static seed nodes.

akka-net-testing-patterns

Write unit and integration tests for Akka.NET actors using modern Akka.Hosting.TestKit patterns. Covers dependency injection, TestProbes, persistence testing, and actor interaction verification. Includes guidance on when to use traditional TestKit.

api-design

Design stable, compatible public APIs using extend-only design principles. Manage API compatibility, wire compatibility, and versioning for NuGet packages and distributed systems.

aspire-configuration

Configure Aspire AppHost to emit explicit app config via environment variables; keep app code free of Aspire clients and service discovery.

aspire-integration-testing

Write integration tests using .NET Aspire

aspire-service-defaults

Create a shared ServiceDefaults project for Aspire applications. Centralizes OpenTelemetry, health checks, resilience, and service discovery configuration across all services.

crap-analysis

Analyze code coverage and CRAP (Change Risk Anti-Patterns) scores to identify high-risk code. Use OpenCover format with ReportGenerator for Risk Hotspots showing cyclomatic complexity and untested code paths.

csharp-concurrency-patterns

Choosing the right concurrency abstraction in .NET - from async/await for I/O to Channels for producer/consumer to Akka.NET for stateful entity management. Avoid locks and manual synchronization unless absolutely necessary.

database-performance

Database access patterns for performance. Separate read/write models, avoid N+1 queries, use AsNoTracking, apply row limits, and never do application-side joins. Works with EF Core and Dapper.

dependency-injection-patterns

Organize DI registrations using IServiceCollection extension methods. Group related services into composable Add* methods for clean Program.cs and reusable configuration in tests.

dotnet-devcert-trust

Diagnose and fix .NET HTTPS dev certificate trust issues on Linux. Covers the full certificate lifecycle from generation to system CA bundle inclusion, with distro-specific guidance for Ubuntu, Fedora, Arch, and WSL2.

dotnet-local-tools

Managing local .NET tools with dotnet-tools.json for consistent tooling across development environments and CI/CD pipelines.

dotnet-project-structure

Modern .NET project structure including .slnx solution format, Directory.Build.props, central package management, SourceLink, version management with RELEASE_NOTES.md, and SDK pinning with global.json.

dotnet-slopwatch

Use Slopwatch to detect LLM reward hacking in .NET code changes. Run after every code modification to catch disabled tests, suppressed warnings, empty catch blocks, and other shortcuts that mask real problems.

efcore-patterns

Entity Framework Core best practices including NoTracking by default, query splitting for navigation collections, migration management, dedicated migration services, and common pitfalls to avoid.

ilspy-decompile

Understand implementation details of .NET code by decompiling assemblies. Use when you want to see how a .NET API works internally, inspect NuGet package source, view framework implementation, or understand compiled .NET binaries.

mailpit-integration

Test email sending locally using Mailpit with .NET Aspire. Captures all outgoing emails without sending them. View rendered HTML, inspect headers, and verify delivery in integration tests.

marketplace-publishing

Workflow for publishing skills and agents to the dotnet-skills Claude Code marketplace. Covers adding new content, updating plugin.json, validation, and release tagging.

相关技能