domain-cloud-native by zhanghandong/rust-skills
npx skills add https://github.com/zhanghandong/rust-skills --skill domain-cloud-native第 3 层:领域约束
| 领域规则 | 设计约束 | Rust 实现含义 |
|---|---|---|
| 12-Factor | 配置来自环境 | 基于环境的配置 |
| 可观测性 | 指标 + 追踪 | tracing + opentelemetry |
| 健康检查 | 存活/就绪 | 专用端点 |
| 优雅关闭 | 干净终止 | 信号处理 |
| 水平扩展 | 无状态设计 | 无本地状态 |
| 容器友好 | 小体积二进制文件 | 发布优化 |
RULE: No local persistent state
WHY: Pods can be killed/rescheduled anytime
RUST: External state (Redis, DB), no static mut
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
RULE: Handle SIGTERM, drain connections
WHY: Zero-downtime deployments
RUST: tokio::signal + graceful shutdown
RULE: Every request must be traceable
WHY: Debugging distributed systems
RUST: tracing spans, opentelemetry export
从约束到设计(第 2 层):
"Need distributed tracing"
↓ m12-lifecycle: Span lifecycle
↓ tracing + opentelemetry
"Need graceful shutdown"
↓ m07-concurrency: Signal handling
↓ m12-lifecycle: Connection draining
"Need health checks"
↓ domain-web: HTTP endpoints
↓ m06-error-handling: Health status
| 用途 | Crate |
|---|---|
| gRPC | tonic |
| Kubernetes | kube, kube-runtime |
| Docker | bollard |
| 追踪 | tracing, opentelemetry |
| 指标 | prometheus, metrics |
| 配置 | config, figment |
| 健康检查 | HTTP endpoints |
| 模式 | 目的 | 实现 |
|---|---|---|
| gRPC 服务 | 服务网格 | tonic + tower |
| K8s 操作符 | 自定义资源 | kube-runtime Controller |
| 可观测性 | 调试 | tracing + OTEL |
| 健康检查 | 编排 | /health, /ready |
| 配置 | 12-factor | 环境变量 + 密钥 |
use tokio::signal;
async fn run_server() -> anyhow::Result<()> {
let app = Router::new()
.route("/health", get(health))
.route("/ready", get(ready));
let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
axum::Server::bind(&addr)
.serve(app.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await?;
Ok(())
}
async fn shutdown_signal() {
signal::ctrl_c().await.expect("failed to listen for ctrl+c");
tracing::info!("shutdown signal received");
}
async fn health() -> StatusCode {
StatusCode::OK
}
async fn ready(State(db): State<Arc<DbPool>>) -> StatusCode {
match db.ping().await {
Ok(_) => StatusCode::OK,
Err(_) => StatusCode::SERVICE_UNAVAILABLE,
}
}
| 错误 | 违反的领域规则 | 修复方法 |
|---|---|---|
| 本地文件状态 | 非无状态 | 外部存储 |
| 无 SIGTERM 处理 | 强制终止 | 优雅关闭 |
| 无追踪 | 无法调试 | tracing spans |
| 静态配置 | 不符合 12-factor | 环境变量 |
| 约束 | 第 2 层模式 | 第 1 层实现 |
|---|---|---|
| 无状态 | 外部状态 | 对外部资源使用 Arc |
| 优雅关闭 | 信号处理 | tokio::signal |
| 追踪 | Span 生命周期 | tracing + OTEL |
| 健康检查 | HTTP 端点 | 专用路由 |
| 何时需要 | 参见 |
|---|---|
| 异步模式 | m07-concurrency |
| HTTP 端点 | domain-web |
| 错误处理 | m13-domain-error |
| 资源生命周期 | m12-lifecycle |
每周安装量
451
代码仓库
GitHub 星标数
912
首次出现
Jan 20, 2026
安全审计
安装于
opencode410
codex395
gemini-cli388
github-copilot378
amp339
kimi-cli335
Layer 3: Domain Constraints
| Domain Rule | Design Constraint | Rust Implication |
|---|---|---|
| 12-Factor | Config from env | Environment-based config |
| Observability | Metrics + traces | tracing + opentelemetry |
| Health checks | Liveness/readiness | Dedicated endpoints |
| Graceful shutdown | Clean termination | Signal handling |
| Horizontal scale | Stateless design | No local state |
| Container-friendly | Small binaries | Release optimization |
RULE: No local persistent state
WHY: Pods can be killed/rescheduled anytime
RUST: External state (Redis, DB), no static mut
RULE: Handle SIGTERM, drain connections
WHY: Zero-downtime deployments
RUST: tokio::signal + graceful shutdown
RULE: Every request must be traceable
WHY: Debugging distributed systems
RUST: tracing spans, opentelemetry export
From constraints to design (Layer 2):
"Need distributed tracing"
↓ m12-lifecycle: Span lifecycle
↓ tracing + opentelemetry
"Need graceful shutdown"
↓ m07-concurrency: Signal handling
↓ m12-lifecycle: Connection draining
"Need health checks"
↓ domain-web: HTTP endpoints
↓ m06-error-handling: Health status
| Purpose | Crate |
|---|---|
| gRPC | tonic |
| Kubernetes | kube, kube-runtime |
| Docker | bollard |
| Tracing | tracing, opentelemetry |
| Metrics | prometheus, metrics |
| Config | config, figment |
| Health | HTTP endpoints |
| Pattern | Purpose | Implementation |
|---|---|---|
| gRPC services | Service mesh | tonic + tower |
| K8s operators | Custom resources | kube-runtime Controller |
| Observability | Debugging | tracing + OTEL |
| Health checks | Orchestration | /health, /ready |
| Config | 12-factor | Env vars + secrets |
use tokio::signal;
async fn run_server() -> anyhow::Result<()> {
let app = Router::new()
.route("/health", get(health))
.route("/ready", get(ready));
let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
axum::Server::bind(&addr)
.serve(app.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await?;
Ok(())
}
async fn shutdown_signal() {
signal::ctrl_c().await.expect("failed to listen for ctrl+c");
tracing::info!("shutdown signal received");
}
async fn health() -> StatusCode {
StatusCode::OK
}
async fn ready(State(db): State<Arc<DbPool>>) -> StatusCode {
match db.ping().await {
Ok(_) => StatusCode::OK,
Err(_) => StatusCode::SERVICE_UNAVAILABLE,
}
}
| Mistake | Domain Violation | Fix |
|---|---|---|
| Local file state | Not stateless | External storage |
| No SIGTERM handling | Hard kills | Graceful shutdown |
| No tracing | Can't debug | tracing spans |
| Static config | Not 12-factor | Env vars |
| Constraint | Layer 2 Pattern | Layer 1 Implementation |
|---|---|---|
| Stateless | External state | Arc for external |
| Graceful shutdown | Signal handling | tokio::signal |
| Tracing | Span lifecycle | tracing + OTEL |
| Health checks | HTTP endpoints | Dedicated routes |
| When | See |
|---|---|
| Async patterns | m07-concurrency |
| HTTP endpoints | domain-web |
| Error handling | m13-domain-error |
| Resource lifecycle | m12-lifecycle |
Weekly Installs
451
Repository
GitHub Stars
912
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode410
codex395
gemini-cli388
github-copilot378
amp339
kimi-cli335
Azure 升级评估与自动化工具 - 轻松迁移 Functions 计划、托管层级和 SKU
64,099 周安装
专业咨询分析技能:AI生成麦肯锡级研究报告,支持市场分析、财务分析、行业研究
430 周安装
Gemini CLI 更新日志自动化流程指南 | 技术文档版本管理最佳实践
430 周安装
tsdown - 基于Rolldown的极速TypeScript/JavaScript库打包工具,支持ESM/CJS/IIFE/UMD
430 周安装
PDF OCR技能:双引擎文字提取,支持影印PDF和图片识别
430 周安装
MUI v7 使用指南:组件样式、主题定制与响应式设计模式详解
431 周安装
HubSpot CRM 集成指南:使用 Membrane CLI 自动化销售、营销与客户服务
431 周安装