欢迎使用 FlowZap,快速、清晰、掌控的绘图应用。

事件驱动发布-订阅架构

Architecture

事件驱动发布-订阅架构图,展示 Kafka 或 RabbitMQ 消息代理、事件序列化、主题分区、向多个消费者的扇出交付以及死信队列错误处理。该模板模拟了生产者和消费者通过消息代理完全解耦的基础异步消息传递模式。对于构建松耦合、可扩展的事件驱动系统的架构师至关重要。

完整 FlowZap 代码

Producer { # Event Producer
n1: circle label:"Business Action"
n2: rectangle label:"Create Domain Event"
n3: rectangle label:"Serialize Event"
n4: rectangle label:"Publish to Topic"
n1.handle(right) -> n2.handle(left)
n2.handle(right) -> n3.handle(left) [label="OrderCreated"]
n3.handle(right) -> n4.handle(left) [label="Avro/JSON"]
n4.handle(bottom) -> Broker.n5.handle(top) [label="Produce"]
}
Broker { # Message Broker (Kafka/RabbitMQ)
n5: rectangle label:"Receive Event"
n6: rectangle label:"Partition by Key"
n7: rectangle label:"Persist to Log"
n8: rectangle label:"Fan-Out to Subscribers"
n9: rectangle label:"Dead Letter Queue"
n5.handle(right) -> n6.handle(left)
n6.handle(right) -> n7.handle(left) [label="Append"]
n7.handle(right) -> n8.handle(left) [label="Notify"]
n8.handle(bottom) -> Consumers.n10.handle(top) [label="Deliver"]
n9.handle(bottom) -> Consumers.n17.handle(top) [label="Failed Events"]
}
Consumers { # Event Consumers
n10: rectangle label:"Inventory Consumer"
n11: rectangle label:"Update Stock Level"
n12: rectangle label:"Notification Consumer"
n13: rectangle label:"Send Order Email"
n14: rectangle label:"Analytics Consumer"
n15: rectangle label:"Update Dashboard"
n16: diamond label:"Processing OK?"
n17: rectangle label:"Retry Handler"
n10.handle(right) -> n16.handle(left)
n16.handle(right) -> n11.handle(left) [label="Yes"]
n16.handle(bottom) -> n17.handle(top) [label="No"]
n17.handle(top) -> Broker.n9.handle(bottom) [label="DLQ"]
n12.handle(right) -> n13.handle(left) [label="Email"]
n14.handle(right) -> n15.handle(left) [label="Aggregate"]
}

为什么需要这个工作流?

Synchronous request-response communication between microservices creates tight coupling, cascading failures, and latency chains. The publish-subscribe pattern decouples producers from consumers through a message broker, enabling independent scaling, temporal decoupling, and resilient event processing with built-in retry mechanisms.

工作原理

  1. Step 1: A business action triggers the creation of a domain event in the producer service.
  2. Step 2: The event is serialized (Avro or JSON) and published to a topic on the message broker.
  3. Step 3: The broker partitions events by key for ordered processing and persists them to a log.
  4. Step 4: Multiple consumers subscribe to the topic and process events independently.
  5. Step 5: Failed events are routed to a dead letter queue after exceeding retry thresholds.
  6. Step 6: Operations teams monitor DLQ depth and investigate failed events through a dashboard.

替代方案

Synchronous HTTP calls are simpler but create coupling. Point-to-point queues limit fan-out. Managed services like AWS SNS/SQS or Google Pub/Sub reduce operational overhead. This template visualizes the complete pub/sub lifecycle including error handling.

Key Facts

Template Name事件驱动发布-订阅架构
CategoryArchitecture
Steps6 workflow steps
FormatFlowZap Code (.fz file)

相关模板

微服务每服务独立数据库架构

Architecture

每服务独立数据库架构图,每个微服务拥有其专用数据存储,通过 Kafka 进行事件驱动同步以实现跨服务数据一致性。该模板展示了微服务数据隔离的核心原则,展示 PostgreSQL 和 MongoDB 如何在多语言持久化策略中共存。对于在保持最终一致性的同时强制服务自治的架构师至关重要。

事件驱动编排架构

Architecture

事件驱动编排架构图,微服务通过事件协调而无需中央编排器,订单、支付、库存和物流服务相互响应对方的领域事件。该模板模拟去中心化协调模式,每个服务只了解自己的职责并发布事件供其他服务消费。适合偏好服务自治而非集中式工作流控制的团队。

事件驱动流处理管道架构

Architecture

实时事件流管道架构图,IoT 传感器、应用日志和用户点击流数据通过 Kafka 流入 Apache Flink 进行窗口聚合、异常检测以及向数据湖和仪表板的多目标输出。该模板可视化从摄取到转换、存储和告警的端到端流处理。对于构建实时分析和监控平台的数据工程师至关重要。

事件驱动死信队列架构

Architecture

死信队列架构图,展示重试策略、指数退避、最大重试阈值、失败消息的 DLQ 路由、运维告警和手动重处理工作流。该模板模拟异步消息系统的关键错误处理模式,确保处理失败时不会静默丢失任何消息。对于构建具有适当故障恢复机制的可靠事件驱动系统至关重要。

API 组合模式架构

Architecture

API 组合架构图,组合器服务向多个微服务扇出并行请求,收集带超时处理的响应,并将结果合并为单一统一响应,支持部分降级。该模板模拟当单个客户端查询需要来自多个服务的数据时使用的 API 组合模式,避免直接的服务间调用。适合在微服务架构中构建聚合层的团队。

事件驱动通知中心架构

Architecture

事件驱动通知中心架构图,展示多源事件摄取、基于模板的消息渲染、按用户偏好路由到邮件(SendGrid/SES)、推送(FCM)、短信(Twilio)和 Slack 渠道,以及交付跟踪和重试机制。该模板模拟将业务服务与交付基础设施解耦的集中式通知系统,支持用户控制偏好的多渠道通信。适合构建可扩展通知基础设施的平台团队。

返回所有模板