pub struct NotifyBroker { /* private fields */ }Expand description
Message broker that distributes PostgreSQL NOTIFY events to subscribers.
Implementations§
Source§impl NotifyBroker
impl NotifyBroker
Sourcepub fn with_capacity(pool: PgPool, capacity: usize) -> Self
pub fn with_capacity(pool: PgPool, capacity: usize) -> Self
Create a new notification broker with custom channel capacity.
Sourcepub async fn start(
&self,
listen_channels: Vec<String>,
) -> Result<(), BrokerError>
pub async fn start( &self, listen_channels: Vec<String>, ) -> Result<(), BrokerError>
Start listening for notifications on the given channels.
This spawns a background task that listens for PostgreSQL NOTIFY events and broadcasts them to all subscribers.
Sourcepub async fn subscribe(
&self,
channel: &str,
) -> Result<Pin<Box<dyn Stream<Item = PgNotification> + Send>>, BrokerError>
pub async fn subscribe( &self, channel: &str, ) -> Result<Pin<Box<dyn Stream<Item = PgNotification> + Send>>, BrokerError>
Subscribe to notifications for a specific channel.
Returns a stream of notifications for the given channel.
Sourcepub async fn subscribe_or_create(
&self,
channel: &str,
) -> Pin<Box<dyn Stream<Item = PgNotification> + Send>>
pub async fn subscribe_or_create( &self, channel: &str, ) -> Pin<Box<dyn Stream<Item = PgNotification> + Send>>
Subscribe to a channel, creating it if it doesn’t exist.
Note: This only creates a broadcast channel. You must also call
listen_channel to start receiving PostgreSQL notifications.
Sourcepub async fn listen_channel(&self, channel: &str) -> Result<(), BrokerError>
pub async fn listen_channel(&self, channel: &str) -> Result<(), BrokerError>
Add a new channel to listen on dynamically.
Sourcepub async fn is_running(&self) -> bool
pub async fn is_running(&self) -> bool
Check if the broker is currently running.
Sourcepub async fn channel_count(&self) -> usize
pub async fn channel_count(&self) -> usize
Get the number of active channels.
Auto Trait Implementations§
impl Freeze for NotifyBroker
impl !RefUnwindSafe for NotifyBroker
impl Send for NotifyBroker
impl Sync for NotifyBroker
impl Unpin for NotifyBroker
impl !UnwindSafe for NotifyBroker
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
Mutably borrows from an owned value. Read more
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>
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 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>
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