Skip to main content

PendingOutbox

Struct PendingOutbox 

Source
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: Value

Domain-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: usize

Zero-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

Source

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.

Source

pub fn caused_by(self, index: usize) -> Self

Set the zero-based index of the event that caused this outbox message.

Source

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).

Source

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

Source§

fn clone(&self) -> PendingOutbox

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 PendingOutbox

Source§

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

Formats the value using the given formatter. Read more

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> 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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