pub struct CommandContext {
pub correlation_id: CorrelationId,
pub conversation_id: ConversationId,
pub process_id: ProcessId,
pub tenant_id: TenantId,
pub workflow_id: WorkflowId,
pub causation_id: Option<CausationId>,
}Expand description
Contextual metadata attached to every command dispatch.
The engine stamps this information onto every event produced by the command. Callers provide the process identity; the engine generates correlation IDs automatically unless provided explicitly.
Fields§
§correlation_id: CorrelationIdSee CorrelationId.
conversation_id: ConversationIdSee ConversationId.
process_id: ProcessIdThe MaKo process instance this command targets.
tenant_id: TenantIdThe tenant that issued this command.
workflow_id: WorkflowIdThe workflow version to use for processing.
causation_id: Option<CausationId>The immediate cause of this command, if driven by a prior event.
Implementations§
Source§impl CommandContext
impl CommandContext
Sourcepub fn new(
tenant_id: TenantId,
process_id: ProcessId,
workflow_id: WorkflowId,
) -> Self
pub fn new( tenant_id: TenantId, process_id: ProcessId, workflow_id: WorkflowId, ) -> Self
Construct a context with auto-generated correlation and conversation IDs.
Sourcepub fn with_causation(self, id: CausationId) -> Self
pub fn with_causation(self, id: CausationId) -> Self
Set an explicit causation ID (e.g. the ID of the event that triggered this command).
Sourcepub fn with_correlation(self, id: CorrelationId) -> Self
pub fn with_correlation(self, id: CorrelationId) -> Self
Override the auto-generated correlation ID.
Use this to propagate a correlation ID from an inbound EDIFACT message so all resulting events share the same root correlation.
Sourcepub fn with_conversation(self, id: ConversationId) -> Self
pub fn with_conversation(self, id: ConversationId) -> Self
Override the auto-generated conversation ID.
Use this to link the outbound APERAK to the same conversation as the UTILMD that triggered it, so the full message exchange is traceable as a unit.
Sourcepub fn from_envelope(env: &EventEnvelope, workflow_id: WorkflowId) -> Self
pub fn from_envelope(env: &EventEnvelope, workflow_id: WorkflowId) -> Self
Build a context that is causally linked to a prior persisted event.
Propagates correlation_id, conversation_id, process_id, and
tenant_id from the envelope and sets the envelope’s event_id as
the causation_id. This is the canonical constructor for all commands
that are triggered by a prior event (e.g. dispatching an APERAK in
response to a received UTILMD).
§Example
let ctx = CommandContext::from_envelope(&utilmd_envelope, workflow_id);
process.execute_with(DispatchAperak { positive: true, reason: None }, ctx).await?;Sourcepub fn from_deadline(deadline: &Deadline, workflow_id: WorkflowId) -> Self
pub fn from_deadline(deadline: &Deadline, workflow_id: WorkflowId) -> Self
Build a context for a deadline-triggered command.
Propagates process_id and tenant_id from the deadline. Generates
fresh correlation_id and conversation_id (deadline firings start
a new tracing root).
§Example
let ctx = CommandContext::from_deadline(&overdue_deadline, workflow_id);
process.execute_with(HandleTimeout { label: overdue_deadline.label().into() }, ctx).await?;Sourcepub fn new_event<E: EventPayload>(
&self,
event: &E,
) -> Result<NewEvent, EngineError>
pub fn new_event<E: EventPayload>( &self, event: &E, ) -> Result<NewEvent, EngineError>
Build a NewEvent from this context and a domain event payload.
This is the canonical way to construct a NewEvent inside a transport
adapter or test helper — it eliminates the nine-argument NewEvent::new
call and ensures that correlation metadata is always propagated correctly.
§Errors
Returns EngineError::Serialization when the event payload cannot be
serialized to JSON.
§Example
// Inside a MessageAdapter or test:
let new_event = ctx.new_event(&SupplierChangeEvent::Activated)?;
store.append(&stream_id, ExpectedVersion::Any, &[new_event]).await?;Trait Implementations§
Source§impl Clone for CommandContext
impl Clone for CommandContext
Source§fn clone(&self) -> CommandContext
fn clone(&self) -> CommandContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more