事件驱动架构 logo

事件驱动架构

Organization
microwind
事件驱动架构

基于事件的异步通信架构,组件通过发布和订阅事件来交互,实现松耦合和高可扩展性。

Overview

Publishermicrowind
Repositoryai-skills
Skill name事件驱动架构
Stars
93
Forks
25
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by microwind on GitHub. Read the source before you install it.

Installation

Install the 事件驱动架构 AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/microwind/ai-skills/tree/main/domain-driven-design/event-driven-architecture
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/microwind/ai-skills.git /tmp/ai-skills
mkdir -p .claude/skills
cp -r /tmp/ai-skills/domain-driven-design/event-driven-architecture .claude/skills/microwind-67
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable 事件驱动架构 in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads 事件驱动架构 on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so 事件驱动架构 is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

事件驱动架构 (Event-Driven Architecture, EDA)

概述

事件驱动架构中,组件通过发布和订阅事件来通信,而非直接调用。

传统:同步调用链
OrderService → InventoryService → PaymentService → NotificationService

事件驱动:发布-订阅
OrderService ──publish──→ [Event Bus] ──subscribe──→ InventoryService
                                      ──subscribe──→ PaymentService
                                      ──subscribe──→ NotificationService

事件类型

类型说明示例
领域事件业务中发生的事实OrderPlaced, PaymentCompleted
集成事件跨服务通信的事件包含其他服务需要的数据
通知事件仅通知,不含详细数据OrderChanged(接收方需要回查)
事件携带状态转移包含完整状态变更OrderPlaced + 所有订单详情

代码示例

java
// 事件定义
public class OrderPlacedEvent {
    private final String orderId;
    private final String customerId;
    private final List<OrderItemDTO> items;
    private final BigDecimal totalAmount;
    private final Instant occurredAt;
}

// 发布者
@Service
public class OrderService {
    private final EventPublisher eventPublisher;

    public void placeOrder(Order order) {
        order.place();
        orderRepo.save(order);
        eventPublisher.publish(new OrderPlacedEvent(
            order.getId(), order.getCustomerId(),
            order.getItems(), order.getTotal()
        ));
    }
}

// 订阅者 — 各自独立处理
@Component
public class InventoryHandler {
    @EventListener
    public void on(OrderPlacedEvent event) {
        for (var item : event.getItems()) {
            inventoryService.reserve(item.getSku(), item.getQuantity());
        }
    }
}

@Component
public class NotificationHandler {
    @EventListener
    public void on(OrderPlacedEvent event) {
        emailService.sendOrderConfirmation(event.getCustomerId(), event.getOrderId());
    }
}

@Component
public class AnalyticsHandler {
    @EventListener
    public void on(OrderPlacedEvent event) {
        analyticsService.trackOrder(event.getOrderId(), event.getTotalAmount());
    }
}
python
# Python 事件驱动
from collections import defaultdict

class EventBus:
    def __init__(self):
        self._handlers = defaultdict(list)

    def subscribe(self, event_type: str, handler):
        self._handlers[event_type].append(handler)

    def publish(self, event_type: str, data: dict):
        for handler in self._handlers[event_type]:
            handler(data)

# 使用
bus = EventBus()
bus.subscribe("order.placed", lambda e: reserve_stock(e["items"]))
bus.subscribe("order.placed", lambda e: send_email(e["customer_id"]))
bus.subscribe("order.placed", lambda e: track_analytics(e))

# 发布一个事件,三个处理器各自执行
bus.publish("order.placed", {"order_id": "123", "items": [...], "customer_id": "456"})

消息中间件选择

中间件特点适用场景
Kafka高吞吐、持久化、回放大规模事件流
RabbitMQ灵活路由、确认机制任务队列、RPC
Redis Streams轻量、低延迟简单事件通知
AWS SNS/SQS托管服务、易扩展云原生应用

EDA 模式

1. 事件通知 (Event Notification)

发送简单通知,接收方按需回查详情
OrderService → { event: "order.placed", orderId: "123" } → InventoryService
InventoryService 收到后调 OrderService API 获取详情

2. 事件携带状态转移 (Event-Carried State Transfer)

事件包含完整数据,接收方无需回查
OrderService → { event: "order.placed", orderId: "123", items: [...], total: 999 }
InventoryService 直接使用事件中的数据

优缺点

✅ 优点

  1. 松耦合 — 发布者不知道谁订阅
  2. 可扩展 — 新增订阅者无需修改发布者
  3. 弹性 — 订阅者故障不影响发布者
  4. 异步 — 非阻塞,提高吞吐

❌ 缺点

  1. 最终一致性 — 非实时,有延迟
  2. 调试困难 — 事件链路追踪复杂
  3. 消息顺序 — 可能乱序到达
  4. 幂等性 — 消费者必须处理重复消息

与其他DDD概念的关系

概念关系
领域事件EDA 的基础是领域事件
CQRS事件驱动更新读模型
Saga模式通过事件编排分布式事务
微服务中的DDD事件是微服务间通信的推荐方式

总结

核心:通过事件发布-订阅实现组件间松耦合的异步通信。

实践:定义清晰的事件契约,保证消费者幂等,使用消息中间件可靠投递,做好事件链路追踪。

Frequently asked questions

What does the 事件驱动架构 AI skill do?

基于事件的异步通信架构,组件通过发布和订阅事件来交互,实现松耦合和高可扩展性。

Why use 事件驱动架构 on TypingMind?

Because you install it once and use it with any model. 事件驱动架构 is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install 事件驱动架构 in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/microwind/ai-skills/tree/main/domain-driven-design/event-driven-architecture. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use 事件驱动架构?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with 事件驱动架构?

As many as you like. As long as a model supports skills, you can use 事件驱动架构 with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the 事件驱动架构 AI skill free?

It is published on GitHub by microwind. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇