Skip to main content

PgmqNotifyClient

Struct PgmqNotifyClient 

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

Unified PGMQ client with comprehensive functionality and notification capabilities

Implementations§

Source§

impl PgmqClient

Source

pub async fn new(database_url: &str) -> Result<Self>

Create new unified PGMQ client using connection string

Source

pub async fn new_with_config( database_url: &str, config: PgmqNotifyConfig, ) -> Result<Self>

Create new unified PGMQ client with custom configuration

Source

pub async fn new_with_pool(pool: PgPool) -> Self

Create new unified PGMQ client using existing connection pool (BYOP - Bring Your Own Pool)

Source

pub async fn new_with_pool_and_config( pool: PgPool, config: PgmqNotifyConfig, ) -> Self

Create new unified PGMQ client with existing pool and custom configuration

Source

pub async fn create_queue(&self, queue_name: &str) -> Result<()>

Create queue if it doesn’t exist

Source

pub async fn send_json_message<T>( &self, queue_name: &str, message: &T, ) -> Result<i64>
where T: Serialize,

Send generic JSON message to queue

Source

pub async fn send_message_with_delay<T>( &self, queue_name: &str, message: &T, delay_seconds: u64, ) -> Result<i64>
where T: Serialize,

Send message with visibility timeout (delay)

Source

pub async fn read_messages( &self, queue_name: &str, visibility_timeout: Option<i32>, limit: Option<i32>, ) -> Result<Vec<Message<Value>>>

Read messages from queue

Source

pub async fn pop_message( &self, queue_name: &str, ) -> Result<Option<Message<Value>>>

Read messages from queue with pop (single read and delete)

Source

pub async fn read_specific_message<T>( &self, queue_name: &str, message_id: i64, visibility_timeout: i32, ) -> Result<Option<Message<T>>>

Read a specific message by ID using custom SQL function (for notification event handling)

Source

pub async fn delete_message( &self, queue_name: &str, message_id: i64, ) -> Result<()>

Delete message from queue

Source

pub async fn archive_message( &self, queue_name: &str, message_id: i64, ) -> Result<()>

Archive message (move to archive)

Source

pub async fn set_visibility_timeout( &self, queue_name: &str, message_id: i64, vt_seconds: i32, ) -> Result<()>

Set visibility timeout for a message

Extends or resets the visibility timeout for a message. This is useful for:

  • Heartbeat during long-running step processing
  • Returning a message to the queue immediately (vt_seconds = 0)
§Arguments
  • queue_name - The queue containing the message
  • message_id - The message ID to update
  • vt_seconds - New visibility timeout in seconds from now
§Returns

Returns Ok(()) on success, or an error if the message doesn’t exist.

Source

pub async fn purge_queue(&self, queue_name: &str) -> Result<u64>

Purge queue (delete all messages)

Source

pub async fn drop_queue(&self, queue_name: &str) -> Result<()>

Drop queue completely

Source

pub async fn queue_metrics(&self, queue_name: &str) -> Result<QueueMetrics>

Get queue metrics/statistics

Source

pub fn pool(&self) -> &PgPool

Get reference to underlying connection pool for advanced operations

Source

pub fn pgmq(&self) -> &PGMQueue

Get reference to pgmq client for direct access

Source

pub fn config(&self) -> &PgmqNotifyConfig

Get the configuration

Source

pub fn has_notify_capabilities(&self) -> bool

Check if this client has notification capabilities enabled

Source

pub async fn health_check(&self) -> Result<bool>

Health check - verify database connectivity

Source

pub async fn get_client_status(&self) -> Result<ClientStatus>

Get client status information

Source

pub fn extract_namespace(&self, queue_name: &str) -> Option<String>

Extract namespace from queue name using configured pattern

Source

pub async fn create_listener( &self, buffer_size: usize, ) -> Result<PgmqNotifyListener>

Create a notify listener for this client

§Arguments
  • buffer_size - MPSC channel buffer size (TAS-51: bounded channels)
§Note

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

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

impl PgmqClient

Helper methods for common queue operations

Source

pub async fn process_namespace_queue( &self, namespace: &str, visibility_timeout: Option<i32>, batch_size: i32, ) -> Result<Vec<Message<Value>>>

Process messages from namespace queue

Source

pub async fn complete_message( &self, namespace: &str, message_id: i64, ) -> Result<()>

Complete message processing (delete from queue)

Source

pub async fn initialize_namespace_queues( &self, namespaces: &[&str], ) -> Result<()>

Initialize standard namespace queues

Source

pub async fn send_with_transaction<T>( &self, queue_name: &str, message: &T, tx: &mut Transaction<'_, Postgres>, ) -> Result<i64>
where T: Serialize,

Send message within a transaction (for atomic operations)

Trait Implementations§

Source§

impl Clone for PgmqClient

Source§

fn clone(&self) -> PgmqClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PgmqClient

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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