pub struct Listener { /* private fields */ }Expand description
Processes events from the event bus.
Listens for events, handles them with registered handlers, and manages retry logic with exponential backoff.
Implementations§
Source§impl Listener
impl Listener
Sourcepub fn new(pool: PgPool, registry: EventHandlerRegistry) -> Self
pub fn new(pool: PgPool, registry: EventHandlerRegistry) -> Self
Creates a new listener with default configuration.
Default settings: 3 max attempts, 15 second base retry duration.
§Arguments
pool- Database connection poolregistry- Registry containing event handlers
Sourcepub fn with_max_attempts(self, max_attempts: u16) -> Self
pub fn with_max_attempts(self, max_attempts: u16) -> Self
Sets maximum retry attempts before moving events to dead letter queue.
§Arguments
max_attempts- Maximum number of processing attempts (1-65535)
Sourcepub fn with_retry_duration(self, retry_duration: Duration) -> Self
pub fn with_retry_duration(self, retry_duration: Duration) -> Self
Sets base duration for exponential backoff retry delays.
Actual delay = base_duration * 2^(attempt - 1)
§Arguments
retry_duration- Base duration for retry calculations
Source§impl Listener
impl Listener
Source§impl Listener
impl Listener
Sourcepub async fn poll(&self, now: DateTime<Utc>) -> Result<Option<Uuid>, Error>
pub async fn poll(&self, now: DateTime<Utc>) -> Result<Option<Uuid>, Error>
Polls for and processes a single event.
Prioritizes unacknowledged events over retry events. Handles the event with registered handlers and manages success/failure reporting.
§Arguments
now- Current timestamp for processing
§Returns
Returns the UUID of the processed event, or None if no events were available.
§Errors
Returns database errors if polling or transaction operations fail.
Source§impl Listener
impl Listener
Sourcepub async fn poll_retryable<'tx>(
tx: &mut PgTransaction<'tx>,
now: DateTime<Utc>,
) -> Result<Option<RawEvent>, Error>
pub async fn poll_retryable<'tx>( tx: &mut PgTransaction<'tx>, now: DateTime<Utc>, ) -> Result<Option<RawEvent>, Error>
Polls for retryable events that are ready for another processing attempt.
Uses FOR UPDATE SKIP LOCKED to atomically claim retryable events while maintaining FIFO ordering and avoiding contention between concurrent listeners.
§Arguments
tx- Database transaction to use for the operationnow- Current timestamp to check against retry deadlines
§Returns
Returns the next retryable event if one is available and ready,
or None if no events are ready for retry.
§Errors
Returns database errors if the query or transaction operations fail.
Auto Trait Implementations§
impl Freeze for Listener
impl !RefUnwindSafe for Listener
impl Send for Listener
impl Sync for Listener
impl Unpin for Listener
impl !UnwindSafe for Listener
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
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>
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>
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