Expand description
Async PostgreSQL LISTEN/NOTIFY pub/sub client built on
tokio-postgres.
§Example
use pgpubsub::{PgPubSub, PgPubSubOptionsBuilder, RecvError};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let options = PgPubSubOptionsBuilder::new("localhost", "mydb", "user", "pass")
.channel_capacity(16)
.build();
let pubsub = PgPubSub::connect(options).await?;
let mut subscription = pubsub.listen("my_channel").await?;
loop {
match subscription.recv().await {
Ok(n) => println!("{}: {}", n.channel, n.payload),
Err(RecvError::Lagged(n)) => eprintln!("lagged, {n} dropped"),
Err(RecvError::Closed) => break,
Err(err) => { eprintln!("{err}"); break; }
}
}
Ok(())
}Modules§
- tokio_
postgres - Re-exports from
tokio_postgresneeded for connection configuration and TLS.
Structs§
- Notification
- Notification will be received when a NOTIFY command was sent on a channel that the client listens to. If there was no payload, the corresponding member will be set to the empty string (and not None for example).
- PgPub
Sub - Client for PostgreSQL LISTEN/NOTIFY pub/sub.
- PgPub
SubOptions - PgPub
SubOptions Builder - Subscription
- A subscription to a PostgreSQL notification channel.
Enums§
- PubSub
Error - Errors returned by
PgPubSuboperations. - Recv
Error - Error returned by
Subscription::recv.