Skip to main content

SagaCommandEnvelope

Struct SagaCommandEnvelope 

Source
pub struct SagaCommandEnvelope {
Show 13 fields pub saga_id: String, pub tenant_id: String, pub workflow: String, pub definition_version: u32, pub definition_digest: String, pub step: String, pub phase: String, pub attempt: u32, pub effect_id: String, pub command_id: String, pub recovery_operation_id: Option<String>, pub payload: Option<Value>, pub raw_payload: Option<SagaPayload>,
}
Expand description

业务作用:Orchestrator 发往参与方的 execute/cancel/compensate/resolve 命令 envelope。

字段说明:payload 只在首步 execute 由启动请求携带;其余命令只携带 Saga 与 step 身份,参与方按 saga_id + step 从本地事实解析业务输入,天然避免敏感载荷跨服务复制。

Fields§

§saga_id: String

实例身份。

§tenant_id: String

规范化租户;无租户部署为固定 system tenant。

§workflow: String

workflow 名称。

§definition_version: u32

实例固定的 definition 版本。

§definition_digest: String

实例固定的 definition 摘要。

§step: String

步骤名称。

§phase: String

执行阶段稳定名(execute/cancel/compensate/resolve)。

§attempt: u32

尝试序号。

§effect_id: String

跨 attempt 稳定的业务效果身份。

§command_id: String

本次尝试的命令身份;同一 attempt 传输重投复用。

§recovery_operation_id: Option<String>

仅由已审计管理操作签发的恢复身份;普通自动命令必须为空。

Participant 只允许携带该字段的新命令重新打开 HALTED 查询或补偿 gate;因此 自动 timeout/new attempt 不能解除人工冻结。旧格式 envelope 缺字段时按 None 解码,支持滚动升级期间继续消费已发布消息。

§payload: Option<Value>

首步 execute 的业务输入;其余命令为空。

§raw_payload: Option<SagaPayload>

原始业务正文;与兼容 JSON payload 互斥,字节与 schema 在重投中保持不变。

Implementations§

Source§

impl SagaCommandEnvelope

Source

pub fn business_payload(&self) -> Result<Option<SagaPayload>>

业务作用:合并兼容 JSON 与原始字节入口为唯一正文合同,拒绝双重正文来源。

参数说明: 无。

返回:原始正文或规范 JSON 字节;重复来源与非法正文返回类型化合同拒绝。

Source

pub fn verify_payload_contract( &self, content_type: &str, schema_id: &str, ) -> Result<()>

业务作用:在 Inbox 和业务解码前按本地 handler 声明复验媒体与 schema。

参数说明:content_type 与 schema_id 来自编译期 descriptor,不来自请求 header。

返回:无正文或合同完全一致时成功;任一漂移返回确定性合同拒绝。

Source

pub fn decode_payload<T: DeserializeOwned>(&self) -> Result<T>

业务作用:把已验证的正文转换为 handler 的类型化输入,二进制合同交付字节数组。

参数说明: 无。

返回:JSON 按原始文本直接解码,二进制保留全部字节;类型不匹配时返回合同拒绝。

Source

pub fn verified(&self) -> Result<VerifiedIdentity>

业务作用:解析并复验命令 envelope 的身份字段。

参数说明: 无。

返回:复验通过返回已证身份;否则返回错误,调用方走隔离路径而不是业务路径。

Source

pub fn verified_for_delivery(&self) -> Result<VerifiedIdentity>

业务作用:在 Kafka 投递边界把命令身份错误转换成封闭分类。

参数说明: 无。

返回:身份合法时返回已证身份;否则只返回稳定的类型化分类,使 transport 不解析 可能包含不可信字段的错误文本,也不让非法命令占用 Participant Inbox。

Source

pub fn to_outbox_event(&self) -> Result<OutboxEvent>

业务作用:把命令 envelope 序列化为 Outbox 事件,与触发它的状态迁移同事务发布。

event_id 直接使用 command_id:同一 attempt 的传输重投必须复用同一投递身份, dispatcher 重发不会产生新的去重身份。

参数说明: 无。

返回:可交给 naoutbox 的事件;序列化失败返回错误。

Trait Implementations§

Source§

impl Clone for SagaCommandEnvelope

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SagaCommandEnvelope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SagaCommandEnvelope

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for SagaCommandEnvelope

Source§

impl PartialEq for SagaCommandEnvelope

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SagaCommandEnvelope

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SagaCommandEnvelope

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more