Skip to main content

SagaCommandService

Trait SagaCommandService 

Source
pub trait SagaCommandService<B: SagaBackend>:
    Send
    + Sync
    + 'static {
    // Required method
    fn handle_saga_command<'a>(
        &'a self,
        runtime: &'a ParticipantRuntime<B>,
        envelope: &'a SagaCommandEnvelope,
        producer: &'a ServiceIdentity,
    ) -> impl Future<Output = Result<ParticipantHandled>> + Send + 'a;

    // Provided method
    fn handle_saga_command_traced<'a>(
        &'a self,
        runtime: &'a ParticipantRuntime<B>,
        envelope: &'a SagaCommandEnvelope,
        producer: &'a ServiceIdentity,
        receipt_trace: Option<&'a TraceContext>,
    ) -> impl Future<Output = Result<ParticipantHandled>> + Send + 'a { ... }
}
Expand description

业务作用:抽象宏生成的类型化步骤分发入口,供 hosted command consumer 绑定具体 Service。

实现只能由 #[saga] 按已发布 descriptor 生成;它必须先执行精确 workflow/version/step 门禁,再进入 ParticipantRuntime 的 Inbox、gate、业务和结果 Outbox 事务序。

Required Methods§

Source

fn handle_saga_command<'a>( &'a self, runtime: &'a ParticipantRuntime<B>, envelope: &'a SagaCommandEnvelope, producer: &'a ServiceIdentity, ) -> impl Future<Output = Result<ParticipantHandled>> + Send + 'a

业务作用:把一条已由 transport 认证并绑定目标 route 的命令交给完整参与方事务 wrapper。

参数说明:

  • runtime: 本服务的参与方运行时。
  • envelope: 已认证且 route 精确匹配的 command envelope。
  • producer: transport 从可信来源映射出的 Orchestrator 逻辑身份。

返回:本地事务 COMMIT 后返回可 ACK 结论;合同、业务瞬态或基础设施错误返回错误。

Provided Methods§

Source

fn handle_saga_command_traced<'a>( &'a self, runtime: &'a ParticipantRuntime<B>, envelope: &'a SagaCommandEnvelope, producer: &'a ServiceIdentity, receipt_trace: Option<&'a TraceContext>, ) -> impl Future<Output = Result<ParticipantHandled>> + Send + 'a

业务作用:携带命令收据链路上下文的类型化分发入口;参与方结果事件由收据派生 子上下文,保持跨服务 trace 连续。

默认实现忽略收据上下文并委托给 handle_saga_command,旧版本宏展开在滚动升级期间 继续满足本 trait;当前宏展开会覆写本方法并把 trace 传入事务 wrapper。

参数说明:

  • runtime: 本服务的参与方运行时。
  • envelope: 已认证且 route 精确匹配的 command envelope。
  • producer: transport 从可信来源映射出的 Orchestrator 逻辑身份。
  • receipt_trace: 收据中已校验的链路上下文;None 表示收据未携带。

返回:语义与 handle_saga_command 一致。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§