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: StringPattern 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: boolWhether 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: usizeMaximum payload size in bytes (pg_notify limit is 8000)
include_metadata: boolWhether to include queue metadata in notifications
Implementations§
Source§impl PgmqNotifyConfig
impl PgmqNotifyConfig
Sourcepub fn with_queue_naming_pattern<S: Into<String>>(self, pattern: S) -> Self
pub fn with_queue_naming_pattern<S: Into<String>>(self, pattern: S) -> Self
Set the queue naming pattern for namespace extraction
Sourcepub fn with_channels_prefix<S: Into<String>>(self, prefix: S) -> Self
pub fn with_channels_prefix<S: Into<String>>(self, prefix: S) -> Self
Set the channels prefix to avoid conflicts
Sourcepub fn with_triggers_enabled(self, enabled: bool) -> Self
pub fn with_triggers_enabled(self, enabled: bool) -> Self
Enable or disable database triggers
Sourcepub fn with_default_namespace<S: Into<String>>(self, namespace: S) -> Self
pub fn with_default_namespace<S: Into<String>>(self, namespace: S) -> Self
Add a default namespace to auto-listen
Sourcepub fn with_default_namespaces<I, S>(self, namespaces: I) -> Self
pub fn with_default_namespaces<I, S>(self, namespaces: I) -> Self
Add multiple default namespaces
Sourcepub fn with_max_payload_size(self, size: usize) -> Self
pub fn with_max_payload_size(self, size: usize) -> Self
Set maximum payload size
Sourcepub fn with_metadata_included(self, include: bool) -> Self
pub fn with_metadata_included(self, include: bool) -> Self
Enable/disable metadata inclusion
Sourcepub fn compiled_pattern(&self) -> Result<Regex>
pub fn compiled_pattern(&self) -> Result<Regex>
Compile the queue naming pattern regex
Sourcepub fn extract_namespace(&self, queue_name: &str) -> Result<String>
pub fn extract_namespace(&self, queue_name: &str) -> Result<String>
Extract namespace from queue name using the configured pattern
Sourcepub fn build_channel_name(&self, base_channel: &str) -> Result<String>
pub fn build_channel_name(&self, base_channel: &str) -> Result<String>
Build channel name with optional prefix, validating the result
Sourcepub fn build_namespace_channel(
&self,
base_channel: &str,
namespace: &str,
) -> Result<String>
pub fn build_namespace_channel( &self, base_channel: &str, namespace: &str, ) -> Result<String>
Build namespace-specific channel name, validating the result
Sourcepub fn queue_created_channel(&self) -> Result<String>
pub fn queue_created_channel(&self) -> Result<String>
Get the queue created channel name
Sourcepub fn message_ready_channel(&self, namespace: &str) -> Result<String>
pub fn message_ready_channel(&self, namespace: &str) -> Result<String>
Get the message ready channel name for a namespace
Sourcepub fn global_message_ready_channel(&self) -> Result<String>
pub fn global_message_ready_channel(&self) -> Result<String>
Get the global message ready channel name
Trait Implementations§
Source§impl Clone for PgmqNotifyConfig
impl Clone for PgmqNotifyConfig
Source§fn clone(&self) -> PgmqNotifyConfig
fn clone(&self) -> PgmqNotifyConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PgmqNotifyConfig
impl Debug for PgmqNotifyConfig
Source§impl Default for PgmqNotifyConfig
impl Default for PgmqNotifyConfig
Source§impl<'de> Deserialize<'de> for PgmqNotifyConfig
impl<'de> Deserialize<'de> for PgmqNotifyConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for PgmqNotifyConfig
impl RefUnwindSafe for PgmqNotifyConfig
impl Send for PgmqNotifyConfig
impl Sync for PgmqNotifyConfig
impl Unpin for PgmqNotifyConfig
impl UnwindSafe for PgmqNotifyConfig
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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