Expand description
PostgreSQL LISTEN/NOTIFY coordination for distributed WarpDrive instances
This module provides distributed coordination using PostgreSQL’s LISTEN/NOTIFY feature. Multiple WarpDrive instances can coordinate cache invalidation, circuit breaker state, rate limits, and health status.
§Architecture
- PgPool: Connection pool for PostgreSQL operations
- PgListener: Long-lived connection for receiving NOTIFY events
- PgNotifier: Publishes NOTIFY events to channels
- PgNotification: Typed notification message with JSON payload
§Example
use warpdrive::postgres::{PgPool, PgListener, PgNotifier};
use warpdrive::config::Config;
let config = Config::from_env()?;
let pool = PgPool::from_config(&config).await?;
// Start listening for cache invalidations
let channels = vec!["warpdrive:cache:invalidate".to_string()];
let mut listener = PgListener::new(&pool, channels).await?;
// Publish a notification
let notifier = PgNotifier::new(pool.clone());
notifier.notify("warpdrive:cache:invalidate", &serde_json::json!({
"key": "user:123"
})).await?;
// Receive notification
use futures::StreamExt;
while let Some(notification) = listener.stream().next().await {
println!("Received: {:?}", notification);
}Structs§
- PgListener
- PostgreSQL LISTEN handler for receiving NOTIFY events
- PgNotification
- Notification received from PostgreSQL LISTEN
- PgNotifier
- PostgreSQL NOTIFY publisher for sending notifications
- PgPool
- PostgreSQL connection pool for distributed coordination
Enums§
- PgError
- Errors that can occur during PostgreSQL operations