pub struct PulsarContext { /* private fields */ }Expand description
The per-delivery context of a Pulsar subscription: this message’s position in the topic’s retained log, and the subscription’s own seeker.
The runtime builds one per dispatched delivery (see BuildContext), and handlers read its
fields by key - Position and SeekHandle - through the Ctx extractor or
ctx.context(..). A body that repositions its own subscription names this type as its C
axis and needs nothing else.
Building it costs no allocation: the position is the delivery’s message id, and the seeker is a clone of the channel to the subscription’s driver task.
§Examples
use ruststream_pulsar::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Job {
id: u64,
rewind: bool,
}
/// Logs where each job sits, and replays the retained backlog when a job asks for it.
#[subscriber(PulsarSubscription::new("jobs", "workers"))]
async fn work(job: &Job, ctx: &mut Context<'_, PulsarContext>) -> HandlerOutcome {
tracing::info!(job = job.id, position = ?ctx.context(Position), "job received");
if job.rewind
&& ctx
.context(SeekHandle)
.seek(PulsarPosition::earliest())
.await
.is_err()
{
return HandlerOutcome::retry();
}
HandlerOutcome::ack()
}Trait Implementations§
Source§impl BuildContext<PulsarMessage> for PulsarContext
impl BuildContext<PulsarMessage> for PulsarContext
Source§fn build(msg: &PulsarMessage) -> Self
fn build(msg: &PulsarMessage) -> Self
Builds the context value by reading fields out of
msg.Source§impl Debug for PulsarContext
impl Debug for PulsarContext
Source§impl Field<PulsarContext> for Position
impl Field<PulsarContext> for Position
Source§type Value<'a> = &'a PulsarPosition
type Value<'a> = &'a PulsarPosition
The value read through this key, borrowed from the source for
'a.Source§fn get(self, src: &PulsarContext) -> &PulsarPosition
fn get(self, src: &PulsarContext) -> &PulsarPosition
Reads this key’s field out of
src.Source§impl Field<PulsarContext> for SeekHandle
impl Field<PulsarContext> for SeekHandle
Source§type Value<'a> = &'a PulsarSeeker
type Value<'a> = &'a PulsarSeeker
The value read through this key, borrowed from the source for
'a.Source§fn get(self, src: &PulsarContext) -> &PulsarSeeker
fn get(self, src: &PulsarContext) -> &PulsarSeeker
Reads this key’s field out of
src.Auto Trait Implementations§
impl Freeze for PulsarContext
impl RefUnwindSafe for PulsarContext
impl Send for PulsarContext
impl Sync for PulsarContext
impl Unpin for PulsarContext
impl UnsafeUnpin for PulsarContext
impl UnwindSafe for PulsarContext
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> 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