Skip to main content

DurableEventQueue

Struct DurableEventQueue 

Source
pub struct DurableEventQueue<T> { /* private fields */ }
Expand description

RocksDB-backed event queue with at-least-once delivery.

Implementations§

Source§

impl<T> DurableEventQueue<T>

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, DurableEventQueueError>

Opens a RocksDB database dedicated to this durable queue.

The database must not be shared with unrelated data. Recovery scans all keys in this DB and treats them as durable queue entries.

Source

pub fn open_with_options<P: AsRef<Path>>( path: P, options: DurableEventQueueOptions, ) -> Result<Self, DurableEventQueueError>

Opens a durable queue with explicit options.

Source

pub fn push(&self, event: T) -> Result<DurableEvent<T>, DurableEventQueueError>

Durably stores event and enqueues it for consumption.

§Partial-failure note

The DB write and the in-memory enqueue are not atomic. If queue.push fails after db.put succeeds (only possible when the internal lock is poisoned), the event is already durable and will be replayed on the next open call. Callers should treat this as at-least-once delivery.

Source

pub fn get( &self, id: u64, ) -> Result<Option<DurableEvent<T>>, DurableEventQueueError>

Reads an unacked event by id without marking it in flight.

Source

pub fn poll(&self) -> Result<Option<DurableEvent<T>>, DurableEventQueueError>

Waits briefly for an available durable event.

Source

pub fn pop(&self) -> Result<Option<DurableEvent<T>>, DurableEventQueueError>

Returns the next available durable event immediately.

Source

pub fn ack(&self, id: u64) -> Result<(), DurableEventQueueError>

Marks an event as handled by deleting it from RocksDB.

This method is intentionally not strict for performance: acking an unknown or already-acked id succeeds because RocksDB deletes are idempotent and avoid an extra read.

Source

pub fn ack_many<I>(&self, ids: I) -> Result<(), DurableEventQueueError>
where I: IntoIterator<Item = u64>,

Marks multiple events as handled with a single RocksDB batch write.

Like ack, this is intentionally not strict: unknown or already-acked ids succeed because RocksDB deletes are idempotent and avoid extra reads.

Source

pub fn nack(&self, id: u64) -> Result<(), DurableEventQueueError>

Re-enqueues an in-flight event at the front of the ready queue without removing it from the durable store. Use this when a consumer cannot handle an event and wants it available for the next poll/pop without restarting.

Source

pub fn len(&self) -> Result<usize, DurableEventQueueError>

Counts unacked events in RocksDB.

This scans the dedicated queue DB, so it is O(n) in the number of unacked events. Prefer using it for diagnostics/tests rather than hot path metrics.

Source

pub fn is_empty(&self) -> Result<bool, DurableEventQueueError>

Returns true when there are no unacked events in RocksDB.

Source

pub fn ready_len(&self) -> Result<usize, DurableEventQueueError>

Counts events currently available for processing.

Source

pub fn iterator(&self) -> DurableEventQueueIterator<'_, T>

Iterates over all unacked events in id order.

Auto Trait Implementations§

§

impl<T> !Freeze for DurableEventQueue<T>

§

impl<T> RefUnwindSafe for DurableEventQueue<T>

§

impl<T> Send for DurableEventQueue<T>
where T: Send,

§

impl<T> Sync for DurableEventQueue<T>
where T: Send,

§

impl<T> Unpin for DurableEventQueue<T>

§

impl<T> UnsafeUnpin for DurableEventQueue<T>

§

impl<T> UnwindSafe for DurableEventQueue<T>

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, 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, 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.