microservice-infrastructure

10
0
Source

微服务基础设施指南,涵盖条件配置、事件驱动架构、服务间通信、国际化与日志等微服务架构的核心基础设施。当用户实现服务间调用、配置多环境、实现异步通信、处理国际化或规范日志输出时使用。

Install

mkdir -p .claude/skills/microservice-infrastructure && curl -L -o skill.zip "https://mcp.directory/api/skills/download/2052" && unzip -o skill.zip -d .claude/skills/microservice-infrastructure && rm skill.zip

Installs to .claude/skills/microservice-infrastructure

About this skill

微服务基础设施指南

Skill 概述

本 Skill 涵盖了 BK-CI 微服务架构中的 4 大核心基础设施,这些是构建分布式系统的基石,与 Spring Cloud/Spring Boot 框架深度集成。

核心主题

主题说明文档
条件配置Profile 配置、特性开关、环境隔离[1-conditional-config.md]
事件驱动MQ 消息队列、发布订阅、异步处理[2-event-driven.md]
服务间通信Feign 客户端、服务发现、熔断降级[3-service-communication.md]
国际化与日志i18n 多语言、日志规范、敏感信息脱敏[4-i18n-logging.md]

微服务基础设施架构

架构视图

┌─────────────────────────────────────────────────────────────────┐
│                    BK-CI 微服务集群                              │
│  Process / Project / Store / Auth / Repository / Dispatch...   │
└─────────────────────────────────────────────────────────────────┘
                             ↓
        ┌────────────────────┼────────────────────┐
        │                    │                    │
   ┌────▼────┐         ┌────▼────┐         ┌────▼────┐
   │ Feign   │         │  MQ     │         │ Config  │
   │ 服务调用 │         │ 事件驱动 │         │ 配置中心 │
   └─────────┘         └─────────┘         └─────────┘
        │                    │                    │
        └────────────────────┼────────────────────┘
                             ↓
┌─────────────────────────────────────────────────────────────────┐
│                    微服务基础设施层                              │
├─────────────────────────────────────────────────────────────────┤
│  • 条件配置(多环境隔离)                                        │
│  • 事件驱动(异步解耦)                                          │
│  • 服务间通信(负载均衡、熔断)                                   │
│  • 国际化与日志(可观测性)                                      │
└─────────────────────────────────────────────────────────────────┘

使用指南

场景 1:配置多环境(开发/测试/生产)

需求: 不同环境使用不同配置、特性开关

步骤:

  1. 查阅 reference/1-conditional-config.md
  2. 使用 @Profile 注解或 @Conditional
  3. 配置 application-{profile}.yml
  4. 实现特性开关逻辑

典型问题:

  • 如何动态切换环境配置?
  • 特性开关如何实现?
  • 配置优先级如何确定?

场景 2:实现事件驱动架构

需求: 异步处理、模块解耦、事件溯源

步骤:

  1. 查阅 reference/2-event-driven.md
  2. 定义事件类(实现 IEvent 接口)
  3. 发布事件到 MQ
  4. 订阅并处理事件

典型问题:

  • 如何发布事件?
  • 如何订阅消息队列?
  • 事件丢失如何处理?

场景 3:服务间调用

需求: 跨服务通信、负载均衡、熔断降级

步骤:

  1. 查阅 reference/3-service-communication.md
  2. 定义 Feign 客户端接口
  3. 配置服务发现(Consul)
  4. 实现熔断降级逻辑

典型问题:

  • Feign 客户端如何定义?
  • 超时时间如何配置?
  • 服务降级如何实现?

场景 4:实现国际化与日志规范

需求: 多语言支持、统一日志格式、敏感信息脱敏

步骤:

  1. 查阅 reference/4-i18n-logging.md
  2. 配置 i18n 消息文件(messages_zh_CN.properties
  3. 规范日志输出(使用 SLF4J)
  4. 实现敏感信息脱敏

典型问题:

  • 如何添加新语言?
  • 日志级别如何设置?
  • 密码等敏感信息如何脱敏?

核心类与文件速查

条件配置

类/文件路径说明
@ProfileSpring Boot 内置环境配置注解
@ConditionalSpring Boot 内置条件化 Bean 加载
application-*.ymlsrc/main/resources/多环境配置文件

事件驱动

类/文件路径说明
IEventcommon-event/pojo/IEvent.kt事件接口
EventDispatchercommon-event/dispatcher/事件分发器
EventListenercommon-event/listener/事件监听器

服务间通信

类/文件路径说明
Clientcommon-client/Client.ktFeign 客户端基类
ServiceXXXResourceapi-*/api/服务接口定义

国际化与日志

目录/文件路径说明
i18n/support-files/i18n/国际化消息文件
messages_*.propertiessupport-files/i18n/多语言配置

开发规范

1. 条件配置规范

  • ✅ 环境相关配置使用 @Profile 注解
  • ✅ 特性开关使用 @ConditionalOnProperty
  • ✅ 敏感配置(密码、密钥)加密存储
  • ✅ 配置文件按环境分离(application-dev.yml

2. 事件驱动规范

  • ✅ 事件类实现 IEvent 接口
  • ✅ 事件命名:{Module}{Action}Event(如 PipelineStartEvent
  • ✅ 事件发布使用 EventDispatcher
  • ✅ 事件监听器处理要幂等
  • ✅ 避免同步等待事件处理结果

3. 服务间通信规范

  • ✅ Feign 接口定义在 api-* 模块
  • ✅ 设置合理的超时时间(连接超时 5s,读超时 30s)
  • ✅ 实现服务降级(返回默认值或缓存数据)
  • ✅ 避免服务间循环调用
  • ✅ 关键调用添加链路追踪

4. 国际化与日志规范

  • ✅ 用户可见文案必须国际化
  • ✅ 至少支持中文和英文
  • ✅ 日志使用 SLF4J(不使用 println
  • ✅ 日志级别:ERROR(错误)、WARN(警告)、INFO(关键流程)、DEBUG(调试)
  • ✅ 敏感信息(密码、Token)必须脱敏

与其他 Skill 的关系

microservice-infrastructure (本 Skill)
    ↓ 依赖
backend-microservice-development     # 微服务开发基础
common-technical-practices           # 通用技术实践
    ↓ 被依赖
process-module-architecture          # Process 模块使用这些基础设施
auth-module-architecture             # Auth 模块使用这些基础设施
...                                  # 其他业务模块

前置知识:

  • backend-microservice-development - 了解 Spring Boot/Spring Cloud 基础

相关 Skill:

  • common-technical-practices - 通用技术实践(AOP、锁、重试)
  • process-module-architecture - Process 模块架构(事件驱动应用)

详细文档导航

文档内容行数典型问题
1-conditional-config.md条件配置59如何配置多环境?特性开关如何实现?
2-event-driven.md事件驱动架构88如何发布事件?事件丢失如何处理?
3-service-communication.md服务间通信104Feign 如何配置?超时如何处理?
4-i18n-logging.md国际化与日志67如何添加新语言?敏感信息如何脱敏?

常见问题 FAQ

Q1: 如何根据环境切换配置?

A:

  1. 创建 application-{profile}.yml(如 application-dev.yml
  2. 启动时指定:--spring.profiles.active=dev
  3. 或使用 @Profile("dev") 注解

Q2: 事件发布后如何保证消费?

A:

  1. 使用 持久化队列(RabbitMQ)
  2. 消费失败后 自动重试
  3. 最终失败进入 死信队列
  4. 监控死信队列并告警

Q3: Feign 调用超时如何处理?

A:

  1. 配置合理的超时时间(连接 5s,读 30s)
  2. 实现 服务降级 返回默认值
  3. 添加 重试机制(幂等操作)
  4. 使用 熔断器 快速失败

Q4: 服务间循环调用如何避免?

A:

  1. 禁止双向依赖(A 调 B,B 不能调 A)
  2. 使用 事件驱动 解耦
  3. 引入 中间服务 打破循环
  4. 代码 Review 时检查依赖关系

Q5: 如何添加新的语言支持?

A:

  1. support-files/i18n/ 下创建 messages_{locale}.properties
  2. 如添加日文:messages_ja_JP.properties
  3. 翻译所有 key 的内容
  4. 重启服务生效

Q6: 日志打印过多影响性能?

A:

  1. 生产环境使用 INFO 级别(不用 DEBUG)
  2. 避免在循环中打印日志
  3. 使用 异步日志(Logback AsyncAppender)
  4. 定期清理旧日志

Q7: 敏感信息如何脱敏?

A:

// 密码脱敏
logger.info("User login: username={}, password={}", username, "******")

// Token 脱敏(显示前4后4)
logger.info("Token: {}...{}", token.take(4), token.takeLast(4))

// 手机号脱敏(显示前3后4)
logger.info("Phone: {}****{}", phone.take(3), phone.takeLast(4))

总结

本 Skill 涵盖了 BK-CI 微服务架构的 4 大核心基础设施,这些是构建分布式系统的基石。

学习路径:

  1. 先了解微服务基础(backend-microservice-development
  2. 按需深入具体技术(配置/事件/通信/日志)
  3. 在实际开发中应用并总结经验

最佳实践:

  • ✅ 多环境隔离使用条件配置
  • ✅ 模块解耦使用事件驱动
  • ✅ 服务间调用实现熔断降级
  • ✅ 用户文案必须国际化
  • ✅ 敏感信息必须脱敏

掌握这些基础设施,让你的微服务架构更加健壮和可维护!🚀

store-module-architecture

TencentBlueKing

Store 研发商店模块架构指南,涵盖插件/模板/镜像管理、版本发布、审核流程、商店市场、扩展点机制。当用户开发研发商店功能、发布插件、管理模板或实现扩展点时使用。

00

00-bkci-global-architecture

TencentBlueKing

BK-CI 全局架构指南,以流水线为核心的模块协作全景图,涵盖完整执行流程、模块依赖关系、数据流向、核心概念。当用户需要理解系统架构、进行跨模块开发、了解模块间协作或规划架构设计时优先阅读。

10

auth-module-architecture

TencentBlueKing

Auth 权限认证模块架构指南,涵盖 IAM 集成、RBAC 权限模型、资源权限校验、权限迁移、OAuth 认证。当用户开发权限功能、配置 IAM 资源、实现权限校验或处理认证流程时使用。

10

go-agent-development

TencentBlueKing

Go Agent 开发指南,涵盖 Agent 架构设计、心跳机制、任务执行、日志上报、升级流程、与 Dispatch 模块交互。当用户开发构建机 Agent、实现任务执行逻辑、处理 Agent 通信或进行 Go 语言开发时使用。

00

supporting-modules-architecture

TencentBlueKing

BK-CI 支撑模块架构指南,涵盖凭证管理(Ticket)、构建机环境(Environment)、通知服务(Notify)、构建日志(Log)、质量红线(Quality)、开放接口(OpenAPI)等支撑性服务模块。当用户开发这些模块功能或需要理解支撑服务架构时使用。

100

git-commit-specification

TencentBlueKing

Git 提交规范,涵盖 commit message 格式(feat/fix/refactor)、Issue 关联、分支命名、PR 提交准备、rebase 使用。当用户提交代码、编写 commit message、创建分支或准备 PR 时使用。

00

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

643969

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

591705

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

318399

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

340397

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

452339

fastapi-templates

wshobson

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.

304231

Stay ahead of the MCP ecosystem

Get weekly updates on new skills and servers.