pub struct JetStreamContext { /* private fields */ }Expand description
Native JetStream per-delivery metadata, built once per delivery from the broker message.
Read its fields by the compile-time keys (for example
keys::STREAM_SEQUENCE). On a core (non-JetStream) delivery there is no such metadata, so the
context is empty and every key reads None; the same handler therefore works on both kinds of
subscription.
The context owns its fields (it copies them out of the delivery), so it does not borrow the message: numbers are a stack copy and the stream/consumer names are cloned once per delivery.
§Examples
use ruststream::schemars::JsonSchema;
use ruststream_nats::context::{JetStreamContext, keys};
use ruststream_nats::prelude::*;
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
struct Order {
id: u64,
}
struct Ledger;
impl Handle<Order, (), (), JetStreamContext> for Ledger {
async fn handle(
&self,
order: &Order,
_outs: &(),
ctx: &mut Context<'_, JetStreamContext>,
) -> Result<(), HandlerOutcome> {
if let Some(sequence) = ctx.context(keys::STREAM_SEQUENCE) {
tracing::info!(order.id, sequence, "entered in the ledger");
}
Ok(())
}
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("ledger", "0.1.0")).with_broker(
NatsBroker::new("nats://localhost:4222"),
|b| {
b.include(subscriber(
JetStreamSubject::new("orders.*", "ORDERS").durable("ledger"),
Ledger,
)
.build());
},
)
}Trait Implementations§
Source§impl BuildContext<NatsMessage> for JetStreamContext
impl BuildContext<NatsMessage> for JetStreamContext
Source§fn build(msg: &NatsMessage) -> Self
fn build(msg: &NatsMessage) -> Self
Builds the context value by reading fields out of
msg.Source§impl Clone for JetStreamContext
impl Clone for JetStreamContext
Source§impl Debug for JetStreamContext
impl Debug for JetStreamContext
Source§impl Default for JetStreamContext
impl Default for JetStreamContext
impl Eq for JetStreamContext
Source§impl Field<JetStreamContext> for StreamSequence
impl Field<JetStreamContext> for StreamSequence
Source§impl Field<JetStreamContext> for ConsumerSequence
impl Field<JetStreamContext> for ConsumerSequence
Source§impl Field<JetStreamContext> for Delivered
impl Field<JetStreamContext> for Delivered
Source§impl Field<JetStreamContext> for Pending
impl Field<JetStreamContext> for Pending
Source§impl Field<JetStreamContext> for Stream
impl Field<JetStreamContext> for Stream
Source§impl Field<JetStreamContext> for Consumer
impl Field<JetStreamContext> for Consumer
Source§impl PartialEq for JetStreamContext
impl PartialEq for JetStreamContext
impl StructuralPartialEq for JetStreamContext
Auto Trait Implementations§
impl Freeze for JetStreamContext
impl RefUnwindSafe for JetStreamContext
impl Send for JetStreamContext
impl Sync for JetStreamContext
impl Unpin for JetStreamContext
impl UnsafeUnpin for JetStreamContext
impl UnwindSafe for JetStreamContext
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