关于 aspire
Aspire Orchestration 技能介绍以代码定义分布式应用拓扑,并编排本地运行及 Azure 部署的工作流,适用于微服务开发者。它支持由不同语言编写的服务,并提供依赖配置、服务发现和本地诊断指引。
主要功能
- 01以代码定义应用资源拓扑
- 02本地启动和编排多个服务
- 03配置数据库、Redis 等依赖
- 04查看日志、追踪和指标
- 05部署到 Azure Container Apps
适用场景
- 01搭建多服务应用的 AppHost
- 02将 Python、Node.js 或 Go 服务纳入编排
- 03在本地查看服务日志和追踪
- 04通过 azd 将应用部署到 Azure
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ rysweet/ amplihack --skill aspire安装后在 Claude Code 中输入/aspire确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
commands.mdexamples.mdpatterns.mdreference.mdtroubleshooting.md详细介绍
Aspire 编排
概述
以代码为先的多语言分布式应用编排。AppHost 定义拓扑,aspire run 在本地进行编排,azd deploy 部署到 Azure。
根据以下关键词自动激活:aspire、微服务、分布式应用、服务发现、编排
快速入门
# Install .NET 8+ and Aspire workload
# See: https://learn.microsoft.com/dotnet/aspire/fundamentals/setup-tooling
dotnet workload update
dotnet workload install aspire
# Create AppHost (orchestrates services in ANY language)
dotnet new aspire-apphost -n MyApp
# Basic AppHost - orchestrate Python, Node.js, .NET services
var builder = DistributedApplication.CreateBuilder(args);
var redis = builder.AddRedis("cache");
// Python service
var pythonApi = builder.AddExecutable("python-api", "python", ".").WithArgs("app.py").WithReference(redis);
// Node.js service
var nodeApi = builder.AddExecutable("node-api", "node", ".").WithArgs("server.js").WithReference(redis);
// .NET service
var dotnetApi = builder.AddProject<Projects.Api>("api").WithReference(redis);
builder.Build().Run();
# Run (orchestrates ALL languages)
aspire run # Dashboard opens at http://localhost:15888
核心工作流
项目设置
dotnet new aspire-apphost -n MyApp
dotnet new webapi -n MyApp.Api
dotnet add MyApp.AppHost reference MyApp.Api
AppHost:在 Program.cs 中定义资源拓扑
ServiceDefaults:共享配置(日志记录、遥测、弹性)
服务:你的应用(API、工作进程、Web 应用)
依赖项配置
// PostgreSQL
var postgres = builder.AddPostgres("db").AddDatabase("mydb");
var api = builder.AddProject<Projects.Api>("api").WithReference(postgres);
// Redis
var redis = builder.AddRedis("cache").WithRedisCommander();
var api = builder.AddProject<Projects.Api>("api").WithReference(redis);
// RabbitMQ
var rabbitmq = builder.AddRabbitMQ("messaging");
var worker = builder.AddProject<Projects.Worker>("worker").WithReference(rabbitmq);
// Access in code (connection strings auto-injected)
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = builder.Configuration.GetConnectionString("cache");
});
本地开发
aspire run # Starts all services
仪表板(localhost:15888):资源、日志、追踪、指标 热重载:代码更改时自动重新构建 调试:通过 IDE 附加到各个服务
云部署
请参阅 Azure 部署指南。
azd init # Initialize Azure Developer CLI
azd up # Deploy (generates Bicep → Azure Container Apps)
azd deploy -e production # Deploy to specific environment
生成内容: Bicep → Container Apps + 网络 + 托管标识
导航指南
设置项目时:
- examples.md 第 8-31 行 → 最简项目
- examples.md 第 518-608 行 → 添加 Python 服务
- examples.md 第 610-669 行 → 添加 Node.js 服务
- examples.md 第 671-768 行 → 添加 Go 服务
添加基础设施时:
- reference.md 第 47-148 行 → 数据库 API(PostgreSQL、Redis、MongoDB)
- examples.md 第 39-95 行 → Redis 集成
- examples.md 第 102-176 行 → PostgreSQL 集成
部署时:
- commands.md 第 215-288 行 → 完整的 azd 工作流
- examples.md 第 387-515 行 → Azure 部署演练
- patterns.md 第 5-42 行 → 高可用配置
调试时:
- troubleshooting.md 第 5-112 行 → 编排故障
- troubleshooting.md 第 291-397 行 → 连接问题
- commands.md 第 131-179 行 → 调试命令
快速参考
**基本命令:**完整参考请参阅 commands.md
多语言模式:
builder.AddProject<Projects.Api>("api"); // .NET
builder.AddExecutable("python-api", "python", ".").WithArgs("app.py"); // Python
builder.AddExecutable("node-api", "node", ".").WithArgs("server.js"); // Node.js
builder.AddExecutable("go-svc", "go", ".").WithArgs("run", "main.go"); // Go
**服务发现:**在 AppHost 中使用 .WithReference(redis) → 在服务中使用 GetConnectionString("cache")
与 Amplihack 集成
命令:/ultrathink "Setup Aspire for microservices"
- prompt-writer 澄清需求 → architect 使用 reference.md 进行 API 设计
- builder 使用 examples.md 实施 → reviewer 参考 patterns.md 检查最佳实践
- tester 使用 troubleshooting.md 进行验证
Agent-Skill 映射:
- architect → reference.md(API 设计)
- builder → examples.md(实施)
- reviewer → patterns.md(最佳实践)
- tester → troubleshooting.md(验证)
- 所有 Agent → commands.md(CLI 操作)
评论
支持 Markdown