Skip to main content

Consumer

Struct Consumer 

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

A consumer of events from a stream

Implementations§

Source§

impl Consumer

Source

pub fn new( db: Arc<AzothDb>, stream: String, name: String, wake_strategy: WakeStrategy, ) -> Result<Self>

Create a new consumer

Source

pub fn with_filter(self, filter: EventFilter) -> Self

Add an additional filter on top of the stream filter

Source

pub fn position(&self) -> Result<Option<u64>>

Get the current cursor position (last acknowledged event ID)

Returns None if no events have been acknowledged yet.

Source

pub fn seek(&mut self, event_id: u64) -> Result<()>

Seek to read from a specific event ID

The next call to next() will return the event at event_id. If event_id is 0, resets to the beginning.

Source

pub fn next(&mut self) -> Result<Option<Event>>

Read the next event (blocking poll)

Returns the next unprocessed event that matches the filter. Call ack() to advance the cursor after processing.

Note: This method is intentionally not implementing Iterator because it returns Result and requires error handling.

Source

pub fn ack(&mut self, event_id: EventId) -> Result<()>

Acknowledge processing of an event (update cursor)

Source

pub async fn ack_async(&mut self, event_id: EventId) -> Result<()>

Acknowledge processing of an event asynchronously (safe for async context)

This is the async-safe version of ack(). Use this when calling from async code to avoid blocking the runtime.

Source

pub fn metadata(&self) -> Result<ConsumerMetadata>

Get consumer metadata

Source

pub fn stream(&self) -> &str

Get the stream name

Source

pub fn name(&self) -> &str

Get the consumer name

Source

pub async fn next_async(&mut self) -> Result<Option<Event>>

Read the next event asynchronously (non-blocking)

This method will wait for new events using the configured wake strategy. With polling (default), it checks periodically. With notifications, it waits for explicit wake-up signals.

Returns the next unprocessed event that matches the filter. Call ack() to advance the cursor after processing.

Source§

impl Consumer

Source

pub fn into_stream(self) -> ConsumerStream

Convert this consumer into an async Stream

The returned stream yields Result<Event> items. After processing each event, call ack() on the stream.

Note: For true async wake-up behavior with notifications, use next_async() directly in a loop instead.

§Example
use futures::StreamExt;

let consumer = bus.subscribe("orders", "processor")?;
let mut stream = consumer.into_stream();

while let Some(result) = stream.next().await {
    let event = result?;
    process(&event).await?;
    stream.ack(event.id)?;
}

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more