pub struct PendingOutbox {
pub message_type: Box<str>,
pub recipient: Box<str>,
pub payload: Value,
pub deliver_after: Option<OffsetDateTime>,
pub payload_schema: Option<Box<str>>,
pub caused_by_event_index: usize,
}Expand description
A lightweight outbox message specification produced by Workflow::handle.
Workflow::handle is a pure function: it cannot know the store-assigned
fields (event_id, stream_id, process_id, etc.) of the events it is
about to emit. PendingOutbox carries only the information the domain
workflow can produce deterministically, without I/O or clock access.
The engine fills in the store-assigned fields after the event append
succeeds, converting PendingOutbox into a fully materialised
OutboxMessage inside SlateDbStore::append_with_outbox.
§Example
// Inside Workflow::handle, when DispatchAperak succeeds:
let outbox = vec![
PendingOutbox::new("APERAK", &state.sender_party_id().to_string(), aperak_payload)
.caused_by(0), // caused by the first event in this batch
];
Ok(WorkflowOutput { events, outbox })Fields§
§message_type: Box<str>EDIFACT or XML message type (e.g. "APERAK", "CONTRL", "REMADV").
recipient: Box<str>GLN or EIC code of the intended recipient market participant.
payload: ValueDomain-level message payload (JSON).
Typically encodes the intent (e.g. positive/negative APERAK reason) rather than the final EDIFACT bytes. The delivery worker or AS4 gateway is responsible for rendering the final wire format.
deliver_after: Option<OffsetDateTime>Do not deliver before this time.
None means deliver immediately (as soon as the delivery worker runs).
Must not use the wall clock inside handle — derive from domain data
only (e.g. a schedule date carried in the command).
payload_schema: Option<Box<str>>BO4E JSON Schema URL that describes the payload shape.
Set this to the canonical BO4E schema URL when the payload is a
BO4E-typed object (e.g. Marktlokation, Messlokation). Leave
None for raw EDIFACT or untyped payloads.
Example:
"https://raw.githubusercontent.com/BO4E/BO4E-Schemas/v202501.0.0/src/bo4e_schemas/bo/Marktlokation.json"
caused_by_event_index: usizeZero-based index into the concurrent events batch that caused this outbound message.
Used by the engine to set causation_event_id on the materialised
OutboxMessage from the stamped EventEnvelope at the same index.
Clamped to events.len() - 1 when out-of-range.
Implementations§
Source§impl PendingOutbox
impl PendingOutbox
Sourcepub fn new(
message_type: impl Into<Box<str>>,
recipient: impl Into<Box<str>>,
payload: Value,
) -> Self
pub fn new( message_type: impl Into<Box<str>>, recipient: impl Into<Box<str>>, payload: Value, ) -> Self
Construct a pending outbox message for immediate delivery.
caused_by_event_index defaults to 0 (first event in the batch).
Chain caused_by to change it.
Sourcepub fn caused_by(self, index: usize) -> Self
pub fn caused_by(self, index: usize) -> Self
Set the zero-based index of the event that caused this outbox message.
Sourcepub fn with_deliver_after(self, deliver_after: OffsetDateTime) -> Self
pub fn with_deliver_after(self, deliver_after: OffsetDateTime) -> Self
Set a deferred delivery time (must be derived from domain data, not
the wall clock, to preserve Workflow::handle purity).
Sourcepub fn with_schema(self, schema_url: &'static str) -> Self
pub fn with_schema(self, schema_url: &'static str) -> Self
Attach a BO4E JSON Schema URL to the payload.
Use this when the payload is a BO4E-typed object so the ERP adapter can deserialise it into the correct type without inspecting the JSON.
Trait Implementations§
Source§impl Clone for PendingOutbox
impl Clone for PendingOutbox
Source§fn clone(&self) -> PendingOutbox
fn clone(&self) -> PendingOutbox
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more