Skip to main content

PgmqNotifyListener

Struct PgmqNotifyListener 

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

PGMQ notification listener using PostgreSQL LISTEN/NOTIFY

Implementations§

Source§

impl PgmqNotifyListener

Source

pub async fn new( pool: PgPool, config: PgmqNotifyConfig, buffer_size: usize, ) -> Result<Self>

Create a new PGMQ notification listener

§Arguments
  • pool - PostgreSQL connection pool
  • config - PGMQ notification configuration
  • buffer_size - MPSC channel buffer size (TAS-51: bounded channels)
§Returns
  • Result<Self> - Configured listener or error
§Note

TAS-51: Migrated from unbounded to bounded channel to prevent OOM during notification bursts. Buffer size should come from:

  • Orchestration: config.mpsc_channels.orchestration.event_listeners.pgmq_event_buffer_size
  • Worker: config.mpsc_channels.worker.event_listeners.pgmq_event_buffer_size
Source

pub fn config(&self) -> &PgmqNotifyConfig

Get the configuration

Source

pub fn stats(&self) -> ListenerStats

Get listener statistics

Source

pub async fn connect(&mut self) -> Result<()>

Connect to the database for listening

Source

pub async fn disconnect(&mut self) -> Result<()>

Disconnect from the database

Source

pub async fn listen_channel(&mut self, channel: &str) -> Result<()>

Listen to a specific channel

Source

pub async fn unlisten_channel(&mut self, channel: &str) -> Result<()>

Stop listening to a specific channel

Source

pub async fn listen_queue_created(&mut self) -> Result<()>

Listen to queue created events

Source

pub async fn listen_message_ready_for_namespace( &mut self, namespace: &str, ) -> Result<()>

Listen to message ready events for a specific namespace

Source

pub async fn listen_message_ready_global(&mut self) -> Result<()>

Listen to all message ready events (global)

Source

pub async fn listen_default_namespaces(&mut self) -> Result<()>

Listen to default namespaces from configuration

Source

pub async fn next_event(&mut self) -> Result<Option<PgmqNotifyEvent>>

Get the next notification event (blocking)

Source

pub async fn listen_with_handler<H>(&mut self, handler: H) -> Result<()>
where H: PgmqEventHandler + 'static,

Start listening loop with an event handler

This function now RUNS THE LOOP IN THE CURRENT TASK and only returns when the underlying notification stream ends or an error occurs. If you want a detached background task, use start_listening_with_handler (see below).

Source

pub async fn start_listening_with_handler<H>( &mut self, handler: H, ) -> Result<JoinHandle<Result<()>>>
where H: PgmqEventHandler + 'static,

Start listening loop with an event handler in a detached background task

This spawns the listener in the background and returns immediately. For applications that need the listener to block until completion, use listen_with_handler instead.

Source

pub async fn start_listening(&mut self) -> Result<()>

Start a simple listening loop that queues events (detached background task)

Source

pub async fn is_healthy(&self) -> bool

Check if the listener is healthy

Source

pub fn listening_channels(&self) -> Vec<String>

Get list of channels currently being listened to

Trait Implementations§

Source§

impl Debug for PgmqNotifyListener

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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