Skip to main content

OutboxMessage

Struct OutboxMessage 

Source
pub struct OutboxMessage {
Show 16 fields pub id: String, pub event_type: String, pub payload: Vec<u8>, pub payload_codec: String, pub payload_codec_version: u16, pub status: OutboxMessageStatus, pub created_at: SystemTime, pub attempts: u32, pub last_error: Option<String>, pub worker_id: Option<String>, pub leased_until: Option<SystemTime>, pub destination: Option<String>, pub metadata: HashMap<String, String>, pub source_aggregate_type: Option<String>, pub source_aggregate_id: Option<String>, pub source_sequence: Option<u64>,
}
Expand description

Durable publication work item stored through the outbox pattern.

The message is an immutable publishable envelope plus mutable delivery state. It is not an aggregate stream; repositories store it in their outbox storage and workers update delivery state directly.

Fields§

§id: String§event_type: String§payload: Vec<u8>§payload_codec: String§payload_codec_version: u16§status: OutboxMessageStatus§created_at: SystemTime§attempts: u32§last_error: Option<String>§worker_id: Option<String>§leased_until: Option<SystemTime>§destination: Option<String>

Optional destination queue for point-to-point delivery via send/listen. When set, the outbox worker uses Sender::send(destination, event) instead of Publisher::publish(event).

§metadata: HashMap<String, String>

Metadata propagated to the publisher (correlation IDs, trace context, etc.).

§source_aggregate_type: Option<String>§source_aggregate_id: Option<String>§source_sequence: Option<u64>

Implementations§

Source§

impl OutboxMessage

Source

pub const RAW_PAYLOAD_CODEC: &'static str = "bytes"

Source

pub const RAW_PAYLOAD_CODEC_VERSION: u16 = 1

Source

pub fn new() -> Self

Source

pub fn create( id: impl Into<String>, event_type: impl Into<String>, payload: Vec<u8>, ) -> SourcedResult<Self>

Create a new outbox message with raw bytes payload.

The event_type names the publishable message, not an aggregate replay record unless the caller intentionally uses the same name.

Source

pub fn create_to( id: impl Into<String>, event_type: impl Into<String>, destination: impl Into<String>, payload: Vec<u8>, ) -> SourcedResult<Self>

Create a new outbox message with raw bytes payload and a destination queue.

When a destination is set, the outbox worker uses Sender::send(destination, event) (point-to-point) instead of Publisher::publish(event) (fan-out).

Source

pub fn encode<T: Serialize>( id: impl Into<String>, event_type: impl Into<String>, payload: &T, ) -> SourcedResult<Self>

Create a new outbox message with bitcode (fast binary) serialization.

Source

pub fn encode_to<T: Serialize>( id: impl Into<String>, event_type: impl Into<String>, destination: impl Into<String>, payload: &T, ) -> SourcedResult<Self>

Create a new outbox message with bitcode serialization and a destination queue.

When a destination is set, the outbox worker uses Sender::send(destination, event) (point-to-point) instead of Publisher::publish(event) (fan-out).

Source

pub fn create_with_metadata( id: impl Into<String>, event_type: impl Into<String>, payload: Vec<u8>, metadata: HashMap<String, String>, ) -> SourcedResult<Self>

Create a message with metadata and raw bytes payload.

Source

pub fn encode_with_metadata<T: Serialize>( id: impl Into<String>, event_type: impl Into<String>, payload: &T, metadata: HashMap<String, String>, ) -> SourcedResult<Self>

Create a message with metadata and bitcode-serialized payload.

Source

pub fn encode_for_entity<T: Serialize>( id: impl Into<String>, event_type: impl Into<String>, payload: &T, entity: &Entity, ) -> SourcedResult<Self>

Create a message that inherits metadata from an entity’s context.

This automatically propagates correlation IDs, trace context, and any other metadata set on the entity, so nothing gets lost between the event store and the bus.

Source

pub fn domain_event<A: Snapshottable>( event_type: impl Into<String>, aggregate: &A, ) -> SourcedResult<Self>

Create a domain-event style message from a Snapshottable aggregate.

This is the recommended way to publish an aggregate-derived fact. It derives everything from the aggregate automatically:

  • id: "{entity_id}:{event_type}:{version}"
  • payload: the aggregate’s snapshot (via create_snapshot())
  • metadata: propagated from the entity (correlation IDs, trace context, etc.)
let outbox = OutboxMessage::domain_event("TodoInitialized", &todo)?;
repo.outbox(outbox).commit(&mut todo).await?;
Source

pub fn decode<T: DeserializeOwned>(&self) -> SourcedResult<T>

Decode the payload from the default binary codec.

Source

pub fn id(&self) -> &str

Source

pub fn payload_str(&self) -> Option<&str>

Source

pub fn is_pending(&self) -> bool

Source

pub fn is_in_flight(&self) -> bool

Source

pub fn is_published(&self) -> bool

Source

pub fn is_failed(&self) -> bool

Source

pub fn has_expired_lease_at(&self, now: SystemTime) -> bool

Source

pub fn is_claimable_at(&self, now: SystemTime) -> bool

Source

pub fn is_claimed_by(&self, worker_id: &str) -> bool

Source

pub fn initialize( &mut self, id: String, event_type: String, payload: Vec<u8>, destination: Option<String>, metadata: HashMap<String, String>, ) -> SourcedResult

Source

pub fn claim(&mut self, worker_id: String, until_secs: u64) -> SourcedResult

Source

pub fn claim_for( &mut self, worker_id: impl Into<String>, lease: Duration, ) -> SourcedResult

Claim with a Duration (convenience method that computes until_secs)

Source

pub fn claim_at( &mut self, worker_id: impl Into<String>, lease: Duration, now: SystemTime, ) -> SourcedResult

Claim with an explicit clock value. This is useful for deterministic tests and repository implementations that capture time once per batch.

Source

pub fn complete(&mut self) -> SourcedResult

Source

pub fn release(&mut self, error: String) -> SourcedResult

Source

pub fn fail(&mut self, error: String) -> SourcedResult

Source

pub fn set_meta(&mut self, key: impl Into<String>, value: impl Into<String>)

Set a single metadata key-value pair.

Source

pub fn set_correlation_id(&mut self, id: impl Into<String>)

Set the correlation ID.

Source

pub fn set_causation_id(&mut self, id: impl Into<String>)

Set the causation ID.

Source

pub fn meta(&self, key: &str) -> Option<&str>

Get a metadata value by key.

Source

pub fn correlation_id(&self) -> Option<&str>

Get the correlation ID, if set.

Source

pub fn causation_id(&self) -> Option<&str>

Get the causation ID, if set.

Source

pub fn set_source<A: Aggregate>(&mut self, aggregate: &A)

Trait Implementations§

Source§

impl Clone for OutboxMessage

Source§

fn clone(&self) -> OutboxMessage

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 OutboxMessage

Source§

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

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

impl Default for OutboxMessage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for OutboxMessage

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 From<&OutboxMessage> for Message

Source§

fn from(outbox: &OutboxMessage) -> Self

Map a durable outbox row to a canonical transport message.

  • id ← outbox message id (the stable durable id);
  • nameevent_type;
  • kindCommand when a point-to-point destination is set, else Event;
  • payload ← raw codec bytes, content_type = application/octet-stream;
  • metadata ← the outbox metadata (correlation/causation/trace/auth) plus framework-derived keys under the reserved SOURCED_METADATA_PREFIX namespace (payload codec, destination, source-aggregate context) so decode/routing context can never be shadowed by a user metadata key.
Source§

impl Serialize for OutboxMessage

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 TableModel for OutboxMessage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateBuilder for T

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<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, 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> Queueable for T

Source§

fn queued(self) -> QueuedRepository<Self, InMemoryAsyncLockManager>

Wrap with the default async lock manager. Pair with .aggregate::<T>() for per-aggregate serialization over the async repository surface.
Source§

fn queued_with<L: AsyncLockManager>( self, lock_manager: L, ) -> QueuedRepository<Self, L>

Wrap with a custom async lock manager.
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.