知识卡片
Saga状态与命令分开提交
需要跟踪进度和补偿历史的Saga可持久化状态,甚至实现为事件溯源聚合。收到的事件与“待执行命令”一起记录,再由类似Outbox的中继异步调用目标端点,避免状态保存与外部命令之间的故障窗口。无状态Saga只是更简单的事件到命令映射,不是所有Saga都无状态。
相关:[[Saga编排跨事务流程]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 通信模式 · 查看原书依据
However, the command execution logic should be moved out of the saga itself and executed asynchronously, similar to the way domain events are dispatched in the outbox pattern: public class CampaignPublishingSaga { private readonly ICampaignRepository _repository; private readonly IList<IDomainEvent> _events; ... public void Process(CampaignActivated activated) { var campaign = _repository.Load(activated.CampaignId); var advertisingMaterials = campaign.GenerateAdvertisingMaterials(); var
参考来源
- 位置:《Learning Domain-Driven Design》第9章《通信模式》(来源项目:book-sources;源文件:extracted/Learning Domain-Driven Design/_epub-src/OEBPS/ch09.html)
- 结论依据:原文围绕本卡所述机制给出定义、适用条件及相关取舍,以下摘录为直接依据。
- 原始内容:However, the command execution logic should be moved out of the saga itself and executed asynchronously, similar to the way domain events are dispatched in the outbox pattern: public class CampaignPublishingSaga { private readonly ICampaignRepository _repository; private readonly IList<IDomainEvent> _events; ... public void Process(CampaignActivated activated) { var campaign = _repository.Load(activated.CampaignId); var advertisingMaterials = campaign.GenerateAdvertisingMaterials(); var