pub struct Message<H, P> {
pub headers: H,
pub body: P,
}Expand description
One incoming message together with its decoded typed header contract.
As a Handle input (Message<OrderHeaders, Order>), the core decodes the
payload and the headers in the same stage, under the same
on_failure(decode = ..) policy as the payload alone, and
the body receives ready values. The pairing is structural: each consumer declares the
contract it reads, so two subscribers of one subject may read different header sets.
As a reply type (Handle<In, Message<EventHeaders, Confirmation>>), the reply’s headers ride
the value: the runtime serializes the contract into the outgoing headers and the payload
through the reply codec.
§Examples
use ruststream::memory::prelude::*;
use serde::Deserialize;
#[derive(Deserialize, schemars::JsonSchema)]
struct OrderHeaders {
tenant: String,
}
#[derive(Deserialize, schemars::JsonSchema)]
struct Order {
id: u64,
}
struct Bill;
/// The payload and its header contract arrive decoded together.
impl Handle<Message<OrderHeaders, Order>> for Bill {
async fn handle(
&self,
msg: &Message<OrderHeaders, Order>,
_outs: &(),
_ctx: &mut Context<'_>,
) -> Result<(), HandlerOutcome> {
tracing::info!(order = msg.body.id, tenant = msg.headers.tenant, "billed");
Ok(())
}
}
fn app() -> RustStream {
RustStream::new(AppInfo::new("billing", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
b.include(subscriber("orders", Bill).build());
})
}Fields§
§headers: HThe decoded header contract.
body: PThe decoded payload.
Implementations§
Trait Implementations§
impl<H, P> Eq for Message<H, P>
Source§impl<H, P> ReplyShape for Message<H, P>
impl<H, P> ReplyShape for Message<H, P>
Source§type Wire = EncodedReply
type Wire = EncodedReply
The reply’s wire:
EncodedReply or SerializedReply.impl<H, P> StructuralPartialEq for Message<H, P>
Auto Trait Implementations§
impl<H, P> Freeze for Message<H, P>
impl<H, P> RefUnwindSafe for Message<H, P>where
H: RefUnwindSafe,
P: RefUnwindSafe,
impl<H, P> Send for Message<H, P>
impl<H, P> Sync for Message<H, P>
impl<H, P> Unpin for Message<H, P>
impl<H, P> UnsafeUnpin for Message<H, P>where
H: UnsafeUnpin,
P: UnsafeUnpin,
impl<H, P> UnwindSafe for Message<H, P>where
H: UnwindSafe,
P: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more