pgwire_replication/client/
mod.rs

1//! PostgreSQL logical replication client.
2//!
3//! This module provides the main interface for consuming logical replication
4//! events from PostgreSQL.
5//!
6//! # Overview
7//!
8//! The client establishes a replication connection to PostgreSQL and streams
9//! change events (inserts, updates, deletes) from the configured publication.
10//!
11//! # Architecture
12//!
13//! ```text
14//! ┌─────────────────┐     channel      ┌─────────────────┐
15//! │                 │◄────────────────│                 │
16//! │  Your App       │  ReplicationEvent│  Worker Task    │
17//! │                 │─────────────────►│                 │
18//! │                 │   applied_lsn    │                 │
19//! └─────────────────┘                  └────────┬────────┘
20//!                                               │
21//!                                               │ TCP/TLS
22//!                                               ▼
23//!                                      ┌─────────────────┐
24//!                                      │   PostgreSQL    │
25//!                                      │  (pgoutput)     │
26//!                                      └─────────────────┘
27//! ```
28//!
29//! # Example
30//!
31//! ```no_run
32//! use pgwire_replication::client::ReplicationClient;
33//! use pgwire_replication::config::ReplicationConfig;
34//! use pgwire_replication::ReplicationEvent;
35//!
36//! #[tokio::main]
37//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
38//!     let config = ReplicationConfig::new(
39//!         "localhost",
40//!         "replicator",
41//!         "password",
42//!         "mydb",
43//!         "my_slot",
44//!         "my_publication",
45//!     );
46//!
47//!     let mut client = ReplicationClient::connect(config).await?;
48//!
49//!     while let Some(event) = client.recv().await? {
50//!         match event {
51//!             ReplicationEvent::XLogData { data, wal_end, .. } => {
52//!                 // Parse and process pgoutput data
53//!                 println!("Received {} bytes at {}", data.len(), wal_end);
54//!
55//!                 // Report progress to allow WAL cleanup
56//!                 client.update_applied_lsn(wal_end);
57//!             }
58//!             ReplicationEvent::KeepAlive { wal_end, .. } => {
59//!                 println!("Server heartbeat at {}", wal_end);
60//!             }
61//!             ReplicationEvent::StoppedAt { reached } => {
62//!                 println!("Reached stop LSN {}", reached);
63//!                 break;
64//!             }
65//!             _ => {}
66//!         }
67//!     }
68//!
69//!     Ok(())
70//! }
71//! ```
72
73mod tokio_client;
74mod worker;
75
76pub use tokio_client::ReplicationClient;
77pub use worker::{ReplicationEvent, ReplicationEventReceiver};