command
Version:
v0.9.2
Opens a new window with list of versions in this module.
Published: Aug 28, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
saga —— 分布式事务 Saga
演示 pkg/orchestration/saga 的顺序正向步骤 + 失败逆序补偿,配合 wallet 幂等键保证补偿不重入。
运行
go run ./examples/saga
说明
- 抽卡流程:扣钻石 → 发卡 → 写记录;示例中发卡服务故障,触发逆序补偿退钻石。
- 每步
Step(name, action, compensate);Execute 遇错自动跑已执行步骤的 compensate。
- 正向/补偿分别用不同幂等键(
tx-draw-1 / tx-refund-1),wallet.ApplyTx 保证重试不会退两次款。
WithCompensationRetry 控制补偿步骤的重试次数。
Documentation
¶
saga 示例:跨服务 Saga 编排(抽卡流程)。
演示 pkg/saga:顺序正向操作 + 失败逆序补偿。流程 "扣钻石 → 发卡 → 写记录",
中途发卡失败,自动逆序补偿(退钻石)。正向/补偿都用 wallet.ApplyTx 的幂等键,
演示 saga + idempotency + wallet 三件套如何咬合(补偿重试不会退两次款)。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.