Skip to main content

PgmqNotifyConfig

Struct PgmqNotifyConfig 

Source
pub struct PgmqNotifyConfig {
    pub queue_naming_pattern: String,
    pub channels_prefix: Option<String>,
    pub enable_triggers: bool,
    pub default_namespaces: HashSet<String>,
    pub max_payload_size: usize,
    pub include_metadata: bool,
}
Expand description

Configuration for PGMQ notification behavior

This struct controls how PGMQ notifications are generated, formatted, and delivered. It allows customization of queue naming patterns, notification channels, and automatic listening behavior.

§Examples

use tasker_pgmq::PgmqNotifyConfig;
use std::collections::HashSet;

// Basic configuration with defaults
let config = PgmqNotifyConfig::new();
assert_eq!(config.queue_naming_pattern, r"(?P<namespace>\w+)_queue");
assert!(!config.enable_triggers); // Triggers disabled by default

// Custom configuration with namespace listening
let mut namespaces = HashSet::new();
namespaces.insert("orders".to_string());
namespaces.insert("inventory".to_string());

let config = PgmqNotifyConfig {
    queue_naming_pattern: r"(?P<namespace>\w+)_messages".to_string(),
    channels_prefix: Some("prod".to_string()),
    enable_triggers: true,
    default_namespaces: namespaces,
    max_payload_size: 4000,
    include_metadata: false,
};

assert_eq!(config.channels_prefix, Some("prod".to_string()));
assert!(config.default_namespaces.contains("orders"));

Fields§

§queue_naming_pattern: String

Pattern for extracting namespace from queue names Should contain a named capture group “namespace” Default: r"(?P<namespace>\w+)_queue" matches “orders_queue” -> “orders”

§channels_prefix: Option<String>

Optional prefix for all notification channels to avoid conflicts Example: “app1” results in channels like “app1.pgmq_queue_created

§enable_triggers: bool

Whether to enable database triggers for automatic notifications If false, relies on application-level emitters

§default_namespaces: HashSet<String>

Default namespaces to auto-listen for message_ready events

§max_payload_size: usize

Maximum payload size in bytes (pg_notify limit is 8000)

§include_metadata: bool

Whether to include queue metadata in notifications

Implementations§

Source§

impl PgmqNotifyConfig

Source

pub fn new() -> Self

Create a new configuration with defaults

Source

pub fn with_queue_naming_pattern<S: Into<String>>(self, pattern: S) -> Self

Set the queue naming pattern for namespace extraction

Source

pub fn with_channels_prefix<S: Into<String>>(self, prefix: S) -> Self

Set the channels prefix to avoid conflicts

Source

pub fn with_triggers_enabled(self, enabled: bool) -> Self

Enable or disable database triggers

Source

pub fn with_default_namespace<S: Into<String>>(self, namespace: S) -> Self

Add a default namespace to auto-listen

Source

pub fn with_default_namespaces<I, S>(self, namespaces: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple default namespaces

Source

pub fn with_max_payload_size(self, size: usize) -> Self

Set maximum payload size

Source

pub fn with_metadata_included(self, include: bool) -> Self

Enable/disable metadata inclusion

Source

pub fn validate(&self) -> Result<()>

Validate the configuration

Source

pub fn compiled_pattern(&self) -> Result<Regex>

Compile the queue naming pattern regex

Source

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

Extract namespace from queue name using the configured pattern

Source

pub fn build_channel_name(&self, base_channel: &str) -> Result<String>

Build channel name with optional prefix, validating the result

Source

pub fn build_namespace_channel( &self, base_channel: &str, namespace: &str, ) -> Result<String>

Build namespace-specific channel name, validating the result

Source

pub fn queue_created_channel(&self) -> Result<String>

Get the queue created channel name

Source

pub fn message_ready_channel(&self, namespace: &str) -> Result<String>

Get the message ready channel name for a namespace

Source

pub fn global_message_ready_channel(&self) -> Result<String>

Get the global message ready channel name

Trait Implementations§

Source§

impl Clone for PgmqNotifyConfig

Source§

fn clone(&self) -> PgmqNotifyConfig

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 PgmqNotifyConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PgmqNotifyConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PgmqNotifyConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for PgmqNotifyConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,