pub trait OutboundInterceptor:
Send
+ Sync
+ 'static {
// Required method
fn name(&self) -> &'static str;
// Provided methods
fn on_send(
&self,
ctx: &OutboundContext<'_>,
runtime_headers: &RuntimeHeaders,
headers: &mut Headers,
message: &dyn Any,
) -> Disposition { ... }
fn on_reply(
&self,
ctx: &OutboundContext<'_>,
runtime_headers: &RuntimeHeaders,
headers: &Headers,
outcome: &Outcome<'_>,
) { ... }
fn on_expand_item(
&self,
ctx: &OutboundContext<'_>,
headers: &Headers,
seq: u64,
item: &dyn Any,
) -> Disposition { ... }
}Expand description
An outbound interceptor that runs on the SENDER side before the message is delivered to the target actor’s mailbox.
Use cases: tracing context propagation, rate limiting, circuit breaking, header stamping, metrics, logging.
Required Methods§
Provided Methods§
Sourcefn on_send(
&self,
ctx: &OutboundContext<'_>,
runtime_headers: &RuntimeHeaders,
headers: &mut Headers,
message: &dyn Any,
) -> Disposition
fn on_send( &self, ctx: &OutboundContext<'_>, runtime_headers: &RuntimeHeaders, headers: &mut Headers, message: &dyn Any, ) -> Disposition
Called before the message is sent. Can modify headers, delay, reject,
or retry. The message body is provided as &dyn Any for inspection.
Sourcefn on_reply(
&self,
ctx: &OutboundContext<'_>,
runtime_headers: &RuntimeHeaders,
headers: &Headers,
outcome: &Outcome<'_>,
)
fn on_reply( &self, ctx: &OutboundContext<'_>, runtime_headers: &RuntimeHeaders, headers: &Headers, outcome: &Outcome<'_>, )
Called when an ask() reply is received back on the sender side. The reply is type-erased — downcast if you know the type.
Note: Not yet wired in TestRuntime — will be connected when the reply path flows through the outbound pipeline (future PR).
Sourcefn on_expand_item(
&self,
ctx: &OutboundContext<'_>,
headers: &Headers,
seq: u64,
item: &dyn Any,
) -> Disposition
fn on_expand_item( &self, ctx: &OutboundContext<'_>, headers: &Headers, seq: u64, item: &dyn Any, ) -> Disposition
Called for each item flowing through a stream or feed on the sender side.
- Stream (server-streaming): called when each reply item arrives back at the caller.
- Feed (client-streaming): called when each input item is about to be sent to the target actor.
seq is a zero-based sequence number within this stream/feed.
The item is type-erased; downcast if you know the concrete type.
Returns Disposition to control per-item flow:
Continue— deliver/forward the item normally.Drop— silently skip this item.Delay(d)— pause fordbefore forwarding (backpressure).Reject(reason)— terminate the stream with an error.Retry(d)— not meaningful for stream items; treated asDrop.