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
impl OutboxMessage
pub const RAW_PAYLOAD_CODEC: &'static str = "bytes"
pub const RAW_PAYLOAD_CODEC_VERSION: u16 = 1
pub fn new() -> Self
Sourcepub fn create(
id: impl Into<String>,
event_type: impl Into<String>,
payload: Vec<u8>,
) -> SourcedResult<Self>
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.
Sourcepub fn create_to(
id: impl Into<String>,
event_type: impl Into<String>,
destination: impl Into<String>,
payload: Vec<u8>,
) -> SourcedResult<Self>
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).
Sourcepub fn encode<T: Serialize>(
id: impl Into<String>,
event_type: impl Into<String>,
payload: &T,
) -> SourcedResult<Self>
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.
Sourcepub fn encode_to<T: Serialize>(
id: impl Into<String>,
event_type: impl Into<String>,
destination: impl Into<String>,
payload: &T,
) -> SourcedResult<Self>
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).
Sourcepub fn create_with_metadata(
id: impl Into<String>,
event_type: impl Into<String>,
payload: Vec<u8>,
metadata: HashMap<String, String>,
) -> SourcedResult<Self>
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.
Sourcepub fn encode_with_metadata<T: Serialize>(
id: impl Into<String>,
event_type: impl Into<String>,
payload: &T,
metadata: HashMap<String, String>,
) -> SourcedResult<Self>
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.
Sourcepub fn encode_for_entity<T: Serialize>(
id: impl Into<String>,
event_type: impl Into<String>,
payload: &T,
entity: &Entity,
) -> SourcedResult<Self>
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.
Sourcepub fn domain_event<A: Snapshottable>(
event_type: impl Into<String>,
aggregate: &A,
) -> SourcedResult<Self>
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?;Sourcepub fn decode<T: DeserializeOwned>(&self) -> SourcedResult<T>
pub fn decode<T: DeserializeOwned>(&self) -> SourcedResult<T>
Decode the payload from the default binary codec.
pub fn id(&self) -> &str
pub fn payload_str(&self) -> Option<&str>
pub fn is_pending(&self) -> bool
pub fn is_in_flight(&self) -> bool
pub fn is_published(&self) -> bool
pub fn is_failed(&self) -> bool
pub fn has_expired_lease_at(&self, now: SystemTime) -> bool
pub fn is_claimable_at(&self, now: SystemTime) -> bool
pub fn is_claimed_by(&self, worker_id: &str) -> bool
pub fn initialize( &mut self, id: String, event_type: String, payload: Vec<u8>, destination: Option<String>, metadata: HashMap<String, String>, ) -> SourcedResult
pub fn claim(&mut self, worker_id: String, until_secs: u64) -> SourcedResult
Sourcepub fn claim_for(
&mut self,
worker_id: impl Into<String>,
lease: Duration,
) -> SourcedResult
pub fn claim_for( &mut self, worker_id: impl Into<String>, lease: Duration, ) -> SourcedResult
Claim with a Duration (convenience method that computes until_secs)
Sourcepub fn claim_at(
&mut self,
worker_id: impl Into<String>,
lease: Duration,
now: SystemTime,
) -> SourcedResult
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.
pub fn complete(&mut self) -> SourcedResult
pub fn release(&mut self, error: String) -> SourcedResult
pub fn fail(&mut self, error: String) -> SourcedResult
Sourcepub fn set_meta(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn set_meta(&mut self, key: impl Into<String>, value: impl Into<String>)
Set a single metadata key-value pair.
Sourcepub fn set_correlation_id(&mut self, id: impl Into<String>)
pub fn set_correlation_id(&mut self, id: impl Into<String>)
Set the correlation ID.
Sourcepub fn set_causation_id(&mut self, id: impl Into<String>)
pub fn set_causation_id(&mut self, id: impl Into<String>)
Set the causation ID.
Sourcepub fn correlation_id(&self) -> Option<&str>
pub fn correlation_id(&self) -> Option<&str>
Get the correlation ID, if set.
Sourcepub fn causation_id(&self) -> Option<&str>
pub fn causation_id(&self) -> Option<&str>
Get the causation ID, if set.
pub fn set_source<A: Aggregate>(&mut self, aggregate: &A)
Trait Implementations§
Source§impl Clone for OutboxMessage
impl Clone for OutboxMessage
Source§fn clone(&self) -> OutboxMessage
fn clone(&self) -> OutboxMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OutboxMessage
impl Debug for OutboxMessage
Source§impl Default for OutboxMessage
impl Default for OutboxMessage
Source§impl<'de> Deserialize<'de> for OutboxMessage
impl<'de> Deserialize<'de> for OutboxMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&OutboxMessage> for Message
impl From<&OutboxMessage> for Message
Source§fn from(outbox: &OutboxMessage) -> Self
fn from(outbox: &OutboxMessage) -> Self
Map a durable outbox row to a canonical transport message.
id← outbox message id (the stable durable id);name←event_type;kind←Commandwhen a point-to-pointdestinationis set, elseEvent;payload← raw codec bytes,content_type=application/octet-stream;metadata← the outbox metadata (correlation/causation/trace/auth) plus framework-derived keys under the reservedSOURCED_METADATA_PREFIXnamespace (payload codec, destination, source-aggregate context) so decode/routing context can never be shadowed by a user metadata key.
Source§impl Serialize for OutboxMessage
impl Serialize for OutboxMessage
Source§impl TableModel for OutboxMessage
impl TableModel for OutboxMessage
fn table_schema() -> TableSchema
fn table_key(&self) -> Result<RowKey, TableStoreError>
fn to_table_row(&self) -> Result<RowValues, TableStoreError>
Auto Trait Implementations§
impl Freeze for OutboxMessage
impl RefUnwindSafe for OutboxMessage
impl Send for OutboxMessage
impl Sync for OutboxMessage
impl Unpin for OutboxMessage
impl UnsafeUnpin for OutboxMessage
impl UnwindSafe for OutboxMessage
Blanket Implementations§
Source§impl<T> AggregateBuilder for T
impl<T> AggregateBuilder for T
fn aggregate<A: Aggregate>(self) -> AggregateRepository<Self, A>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Queueable for T
impl<T> Queueable for T
Source§fn queued(self) -> QueuedRepository<Self, InMemoryAsyncLockManager>
fn queued(self) -> QueuedRepository<Self, InMemoryAsyncLockManager>
.aggregate::<T>() for per-aggregate serialization over the async
repository surface.