Skip to main content

PostOffice

Struct PostOffice 

Source
pub struct PostOffice { /* private fields */ }
Expand description

The messaging client. Cheap to clone; holds a handle to the Platform.

Implementations§

Source§

impl PostOffice

Source

pub fn new(platform: &Platform) -> Self

Source

pub async fn send(&self, event: EventEnvelope) -> Result<(), AppError>

Fire-and-forget delivery to event.to (Java po.send). Errors: 400 when to is missing, 404 when the route is not registered. Awaits when the route’s bounded manager mailbox is full — reactive back-pressure, not drops.

When called from inside a traced function, the platform propagates the trace automatically: the outbound event carries the current trace id/path, this function’s span id (the receiver’s parent span), the sender route, and the business correlation-id when the event has none.

A route declared in yaml.event.over.http forwards transparently to the peer’s /api/event instead of the local bus (Java EventEmitter.send declarative hook) — user code cannot tell a remote route from a local one. The x-event-api envelope header marks an event that already crossed the wire, so it is never re-forwarded.

Source

pub fn send_later(&self, event: EventEnvelope, delay: Duration) -> String

Schedule a future one-time delivery (Java po.sendLater(event, time)): the event is sent after delay; the returned timer id cancels it via cancel_future_event. The timer rides an abortable tokio task (map-don’t-mirror; increment E-3 — built for the event-script flow TTL watcher).

Source

pub fn cancel_future_event(&self, timer_id: &str) -> bool

Cancel a scheduled delivery (Java po.cancelFutureEvent(id)). Returns whether the timer was still pending.

Source

pub fn my_correlation_id(&self) -> Option<String>

The business correlation-id of the current traced request (Java getMyCorrelationId). None outside a trace or when the incoming event carried none.

Source

pub fn my_trace_id(&self) -> Option<String>

The current trace id (Java getTraceId on the trace-aware PostOffice).

Source

pub fn my_trace_path(&self) -> Option<String>

The current trace path.

Source

pub fn my_span_id(&self) -> Option<String>

The current hop’s own span id (Java getTrace().spanId) — what a function stamps as the parent of the NEXT hop when it carries the trace context across a non-event boundary (e.g. a Kafka record’s W3C traceparent header). None outside a trace or in a zero-traced hop, which owns no span.

Source

pub fn annotate_trace(&self, key: &str, value: impl Serialize) -> &Self

Attach business context to the distributed-trace dataset that flows to the telemetry sink (Java annotateTrace). Silent no-op outside a trace.

Source

pub fn update_context( &self, key: &str, value: impl Serialize, ) -> Result<(), AppError>

Attach business context to the application log stream only (Java updateContext) — appears in the context block of every subsequent structured log line of this request. A null value removes the key. The reserved keys — the trace-context names in both spellings (cid, traceId / trace_id, tracePath / trace_path, spanId / span_id, parentSpanId / parent_span_id, service, utc, timestamp) — are rejected with a 400; outside a trace the call is a silent no-op. A key the template also emits never shadows the template: the template wins.

Source

pub async fn request( &self, event: EventEnvelope, timeout: Duration, ) -> Result<EventEnvelope, AppError>

RPC (Java po.request(event, timeout)): deliver the event and await the reply through a temporary inbox. Timeout → status 408.

A route declared in yaml.event.over.http forwards transparently as an Event-over-HTTP RPC and returns the peer’s reply (Java EventEmitter.asyncRequest/eRequest declarative hook); the x-event-api recursion guard applies as in send.

Trait Implementations§

Source§

impl Clone for PostOffice

Source§

fn clone(&self) -> Self

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

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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