首页/ AI 技能 / @skilllib/skill-2117939930272418043
Skill站外收录 @skilllib/skill-2117939930272418043

transport

统一微服务通信规范,通过 gRPC 实现高性能同步调用,借助 RabbitMQ 支持异步事件驱动,所有接口契约集中管理于共享库,强制语义化版本控制与标准化异常处理机制。

0.0 (0) 12 次安装 原作者 编程导航
收录于 2026-01-22
软件开发 AI 技能

Skills.MD

# Microservices & Transport Standards ## **Priority: P0 (FOUNDATIONAL)** Microservices communication patterns and transport layer standards. - **Synchronous (RPC)**: Use **gRPC** for low-latency, internal service-to-service calls. - **Why**: 10x faster than REST/JSON, centralized `.proto` contracts. - **Asynchronous (Events)**: Use **RabbitMQ** or **Kafka** for decoupling domains. - **Pattern**: Fire-and-forget (`emit()`) for side effects (e.g., "UserCreated" -> "SendEmail"). ## Monorepo Architecture - **Contracts**: - **Pattern**: Store all DTOs, `.proto` files, and Interfaces in a **Shared Library** (`libs/contracts`). - **Rule**: Services never import code from other services. They only import from `contracts`. - **Versioning**: Semantic versioning of messages is mandatory. Never change a field type; add a new field. ## Exception Handling - **Propagation**: Standard `HttpException` is lost over Rpc/Tcp. - **Standard**: Use `RpcException` and generic Filters. ```typescript // Global RPC Filter @Catch() export class RpcExceptionFilter implements RpcExceptionFilter<RpcException> { catch(exception: RpcException, host: ArgumentsHost): Observable<any> { return throwError(() => exception.getError()); } } ``` ## Serialization - **Message DTOs**: Use `class-validator` just like HTTP. - **Config**: Apply `useGlobalPipes(new ValidationPipe({ transform: true }))` in the `MicroserviceOptions` setup, not just HTTP app setup.

评论 0

还没有评论,来抢沙发。