Microservice Infrastructure Guide
Skill Overview
This Skill covers 4 core infrastructure components in the BK-CI microservice architecture, which are the cornerstones of building distributed systems and deeply integrated with the Spring Cloud/Spring Boot framework.
Core Topics
| Topic | Description | Document |
|---|
| Conditional Configuration | Profile configuration, feature flags, environment isolation | [1-conditional-config.md] |
| Event-Driven | MQ message queue, publish-subscribe, asynchronous processing | [2-event-driven.md] |
| Inter-Service Communication | Feign client, service discovery, circuit breaking and degradation | [3-service-communication.md] |
| Internationalization & Logging | i18n multi-language, logging specifications, sensitive information desensitization | [4-i18n-logging.md] |
Microservice Infrastructure Architecture
Architecture View
┌─────────────────────────────────────────────────────────────────┐
│ BK-CI 微服务集群 │
│ Process / Project / Store / Auth / Repository / Dispatch... │
└─────────────────────────────────────────────────────────────────┘
↓
┌────────────────────┼────────────────────┐
│ │ │
┌────▼────┐ ┌────▼────┐ ┌────▼────┐
│ Feign │ │ MQ │ │ Config │
│ 服务调用 │ │ 事件驱动 │ │ 配置中心 │
└─────────┘ └─────────┘ └─────────┘
│ │ │
└────────────────────┼────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────┐
│ 微服务基础设施层 │
├─────────────────────────────────────────────────────────────────┤
│ • 条件配置(多环境隔离) │
│ • 事件驱动(异步解耦) │
│ • 服务间通信(负载均衡、熔断) │
│ • 国际化与日志(可观测性) │
└─────────────────────────────────────────────────────────────────┘
Usage Guide
Scenario 1: Configure Multi-Environments (Development/Testing/Production)
Requirement: Use different configurations and feature flags for different environments
Steps:
- Refer to reference/1-conditional-config.md
- Use annotation or
- Configure
application-{profile}.yml
- Implement feature flag logic
Typical Questions:
- How to dynamically switch environment configurations?
- How to implement feature flags?
- How to determine configuration priority?
Scenario 2: Implement Event-Driven Architecture
Requirement: Asynchronous processing, module decoupling, event sourcing
Steps:
- Refer to reference/2-event-driven.md
- Define event class (implement interface)
- Publish events to MQ
- Subscribe to and process events
Typical Questions:
- How to publish events?
- How to subscribe to message queues?
- How to handle event loss?
Scenario 3: Inter-Service Calls
Requirement: Cross-service communication, load balancing, circuit breaking and degradation
Steps:
- Refer to reference/3-service-communication.md
- Define Feign client interface
- Configure service discovery (Consul)
- Implement circuit breaking and degradation logic
Typical Questions:
- How to define Feign clients?
- How to configure timeout settings?
- How to implement service degradation?
Scenario 4: Implement Internationalization & Logging Specifications
Requirement: Multi-language support, unified log format, sensitive information desensitization
Steps:
- Refer to reference/4-i18n-logging.md
- Configure i18n message files (
messages_zh_CN.properties
)
- Standardize log output (use SLF4J)
- Implement sensitive information desensitization
Typical Questions:
- How to add new languages?
- How to set log levels?
- How to desensitize sensitive information like passwords?
Quick Reference for Core Classes & Files
Conditional Configuration
| Class/File | Path | Description |
|---|
| Built-in in Spring Boot | Environment configuration annotation |
| Built-in in Spring Boot | Conditional Bean loading |
| | Multi-environment configuration files |
Event-Driven
| Class/File | Path | Description |
|---|
| common-event/pojo/IEvent.kt
| Event interface |
| | Event dispatcher |
| | Event listener |
Inter-Service Communication
| Class/File | Path | Description |
|---|
| | Feign client base class |
| | Service interface definition |
Internationalization & Logging
| Directory/File | Path | Description |
|---|
| | Internationalization message files |
| | Multi-language configuration |
Development Specifications
1. Conditional Configuration Specifications
- ✅ Use annotation for environment-related configurations
- ✅ Use for feature flags
- ✅ Encrypt and store sensitive configurations (passwords, keys)
- ✅ Separate configuration files by environment ()
2. Event-Driven Specifications
- ✅ Event classes must implement the interface
- ✅ Event naming: (e.g., )
- ✅ Use to publish events
- ✅ Event listener processing must be idempotent
- ✅ Avoid synchronous waiting for event processing results
3. Inter-Service Communication Specifications
- ✅ Define Feign interfaces in modules
- ✅ Set reasonable timeout values (5s connection timeout, 30s read timeout)
- ✅ Implement service degradation (return default values or cached data)
- ✅ Avoid circular calls between services
- ✅ Add distributed tracing for critical calls
4. Internationalization & Logging Specifications
- ✅ All user-visible text must be internationalized
- ✅ Support at least Chinese and English
- ✅ Use SLF4J for logging (do not use )
- ✅ Log levels: ERROR (errors), WARN (warnings), INFO (critical processes), DEBUG (debugging)
- ✅ Sensitive information (passwords, Tokens) must be desensitized
Relationship with Other Skills
microservice-infrastructure (this Skill)
↓ depends on
backend-microservice-development # Microservice Development Basics
common-technical-practices # Common Technical Practices
↓ is depended by
process-module-architecture # Process module uses these infrastructures
auth-module-architecture # Auth module uses these infrastructures
... # Other business modules
Prerequisite Knowledge:
backend-microservice-development
- Understand Spring Boot/Spring Cloud basics
Related Skills:
common-technical-practices
- Common Technical Practices (AOP, locks, retries)
process-module-architecture
- Process Module Architecture (event-driven application)
Detailed Document Navigation
| Document | Content | Line Count | Typical Questions |
|---|
| 1-conditional-config.md | Conditional Configuration | 59 | How to configure multi-environments? How to implement feature flags? |
| 2-event-driven.md | Event-Driven Architecture | 88 | How to publish events? How to handle event loss? |
| 3-service-communication.md | Inter-Service Communication | 104 | How to configure Feign? How to handle timeouts? |
| 4-i18n-logging.md | Internationalization & Logging | 67 | How to add new languages? How to desensitize sensitive information? |
FAQ
Q1: How to switch configurations based on environment?
A:
- Create
application-{profile}.yml
(e.g., )
- Specify at startup:
--spring.profiles.active=dev
- Or use the annotation
Q2: How to ensure consumption after event publishing?
A:
- Use persistent queues (RabbitMQ)
- Automatic retry after consumption failure
- Failed messages enter the dead-letter queue eventually
- Monitor the dead-letter queue and set up alerts
Q3: How to handle Feign call timeouts?
A:
- Configure reasonable timeout values (5s connection, 30s read)
- Implement service degradation to return default values
- Add retry mechanism (for idempotent operations)
- Use circuit breakers for fast failure
Q4: How to avoid circular calls between services?
A:
- Prohibit bidirectional dependencies (if A calls B, B cannot call A)
- Use event-driven approach for decoupling
- Introduce intermediate services to break the cycle
- Check dependency relationships during code review
Q5: How to add new language support?
A:
- Create
messages_{locale}.properties
under
- For example, add Japanese:
messages_ja_JP.properties
- Translate the content of all keys
- Restart the service to take effect
Q6: Excessive log printing affects performance?
A:
- Use INFO level in production environment (do not use DEBUG)
- Avoid printing logs in loops
- Use asynchronous logging (Logback AsyncAppender)
- Regularly clean up old logs
Q7: How to desensitize sensitive information?
A:
kotlin
// Password desensitization
logger.info("User login: username={}, password={}", username, "******")
// Token desensitization (show first 4 and last 4 characters)
logger.info("Token: {}...{}", token.take(4), token.takeLast(4))
// Phone number desensitization (show first 3 and last 4 characters)
logger.info("Phone: {}****{}", phone.take(3), phone.takeLast(4))
Summary
This Skill covers 4 core infrastructure components of the BK-CI microservice architecture, which are the cornerstones of building distributed systems.
Learning Path:
- First understand microservice basics (
backend-microservice-development
)
- Dive into specific technologies as needed (configuration/events/communication/logging)
- Apply in actual development and summarize experience
Best Practices:
- ✅ Use conditional configuration for multi-environment isolation
- ✅ Use event-driven approach for module decoupling
- ✅ Implement circuit breaking and degradation for inter-service calls
- ✅ All user-facing text must be internationalized
- ✅ Sensitive information must be desensitized
Mastering these infrastructures will make your microservice architecture more robust and maintainable! 🚀