pub struct PgmqNotifyListener { /* private fields */ }Expand description
PGMQ notification listener using PostgreSQL LISTEN/NOTIFY
Implementations§
Source§impl PgmqNotifyListener
impl PgmqNotifyListener
Sourcepub async fn new(
pool: PgPool,
config: PgmqNotifyConfig,
buffer_size: usize,
) -> Result<Self>
pub async fn new( pool: PgPool, config: PgmqNotifyConfig, buffer_size: usize, ) -> Result<Self>
Create a new PGMQ notification listener
§Arguments
pool-PostgreSQLconnection poolconfig- PGMQ notification configurationbuffer_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
Sourcepub fn config(&self) -> &PgmqNotifyConfig
pub fn config(&self) -> &PgmqNotifyConfig
Get the configuration
Sourcepub fn stats(&self) -> ListenerStats
pub fn stats(&self) -> ListenerStats
Get listener statistics
Sourcepub async fn disconnect(&mut self) -> Result<()>
pub async fn disconnect(&mut self) -> Result<()>
Disconnect from the database
Sourcepub async fn listen_channel(&mut self, channel: &str) -> Result<()>
pub async fn listen_channel(&mut self, channel: &str) -> Result<()>
Listen to a specific channel
Sourcepub async fn unlisten_channel(&mut self, channel: &str) -> Result<()>
pub async fn unlisten_channel(&mut self, channel: &str) -> Result<()>
Stop listening to a specific channel
Sourcepub async fn listen_queue_created(&mut self) -> Result<()>
pub async fn listen_queue_created(&mut self) -> Result<()>
Listen to queue created events
Sourcepub async fn listen_message_ready_for_namespace(
&mut self,
namespace: &str,
) -> Result<()>
pub async fn listen_message_ready_for_namespace( &mut self, namespace: &str, ) -> Result<()>
Listen to message ready events for a specific namespace
Sourcepub async fn listen_message_ready_global(&mut self) -> Result<()>
pub async fn listen_message_ready_global(&mut self) -> Result<()>
Listen to all message ready events (global)
Sourcepub async fn listen_default_namespaces(&mut self) -> Result<()>
pub async fn listen_default_namespaces(&mut self) -> Result<()>
Listen to default namespaces from configuration
Sourcepub async fn next_event(&mut self) -> Result<Option<PgmqNotifyEvent>>
pub async fn next_event(&mut self) -> Result<Option<PgmqNotifyEvent>>
Get the next notification event (blocking)
Sourcepub async fn listen_with_handler<H>(&mut self, handler: H) -> Result<()>where
H: PgmqEventHandler + 'static,
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).
Sourcepub async fn start_listening_with_handler<H>(
&mut self,
handler: H,
) -> Result<JoinHandle<Result<()>>>where
H: PgmqEventHandler + 'static,
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.
Sourcepub async fn start_listening(&mut self) -> Result<()>
pub async fn start_listening(&mut self) -> Result<()>
Start a simple listening loop that queues events (detached background task)
Sourcepub async fn is_healthy(&self) -> bool
pub async fn is_healthy(&self) -> bool
Check if the listener is healthy
Sourcepub fn listening_channels(&self) -> Vec<String>
pub fn listening_channels(&self) -> Vec<String>
Get list of channels currently being listened to
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PgmqNotifyListener
impl !RefUnwindSafe for PgmqNotifyListener
impl Send for PgmqNotifyListener
impl Sync for PgmqNotifyListener
impl Unpin for PgmqNotifyListener
impl !UnwindSafe for PgmqNotifyListener
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