Skip to main content

pgwire_replication/
lib.rs

1//! # pgwire-replication
2//!
3//! A Tokio-based PostgreSQL logical replication client implementing the pgoutput protocol.
4//!
5//! ## Features
6//!
7//! - **Async/await** - Built on Tokio for high-performance async I/O
8//! - **TLS support** - Optional rustls-based encryption with verify modes
9//! - **SCRAM-SHA-256** - Secure password authentication
10//! - **pgoutput protocol** - Native logical replication decoding
11//!
12//! ## Quick Start
13//!
14//! ```rust,no_run
15//! use pgwire_replication::{ReplicationClient, ReplicationConfig, ReplicationEvent, Lsn};
16//! use std::time::Duration;
17//!
18//! # async fn example() -> anyhow::Result<()> {
19//! let config = ReplicationConfig {
20//!     host: "localhost".into(),
21//!     port: 5432,
22//!     user: "postgres".into(),
23//!     password: "secret".into(),
24//!     database: "mydb".into(),
25//!     slot: "my_slot".into(),
26//!     publication: "my_publication".into(),
27//!     start_lsn: Lsn::ZERO,
28//!     ..Default::default()
29//! };
30//!
31//! let mut client = ReplicationClient::connect(config).await?;
32//!
33//! while let Some(ev) = client.recv().await? {
34//!     match ev {
35//!         ReplicationEvent::XLogData { wal_end, data, .. } => {
36//!             println!("Got data at {}: {} bytes", wal_end, data.len());
37//!         }
38//!         ReplicationEvent::KeepAlive { wal_end, .. } => {
39//!             println!("Keepalive at {}", wal_end);
40//!         }
41//!         ReplicationEvent::Message { prefix, content, .. } => println!(
42//!             "Logical message: prefix={}, {} bytes",
43//!             String::from_utf8_lossy(&prefix),
44//!             content.len()
45//!         ),
46//!         ReplicationEvent::StoppedAt {reached: _} => break,
47//!         ReplicationEvent::Begin { .. } => println!(
48//!             "Transaction start, probably want to flush in-flight events to the sinks."
49//!         ),
50//!         ReplicationEvent::Commit { .. } => println!(
51//!             "Transanction finished, good time to store a checkpoint at the higher level."
52//!         ),
53//!     }
54//! }
55//! # Ok(())
56//! # }
57//! ```
58//!
59//! ## Feature Flags
60//!
61//! - `tls-rustls` (default) - TLS support via rustls
62//! - `scram` (default) - SCRAM-SHA-256 authentication
63//! - `md5` - MD5 authentication (legacy)
64
65#![warn(
66    clippy::all,
67    clippy::cargo,
68    clippy::perf,
69    clippy::style,
70    clippy::correctness,
71    clippy::suspicious
72)]
73#![allow(
74    clippy::module_name_repetitions,
75    clippy::missing_errors_doc,
76    clippy::missing_panics_doc,
77    clippy::must_use_candidate,
78    clippy::multiple_crate_versions
79)]
80
81pub mod auth;
82pub mod client;
83pub mod config;
84pub mod error;
85pub mod lsn;
86pub mod protocol;
87pub mod tls;
88
89pub use client::{
90    create_logical_slot, AppliedLsnHandle, CreatedSlot, ReplicationClient, ReplicationEvent,
91    ReplicationEventReceiver, SlotSnapshot, WireBytesGuard,
92};
93pub use config::{ExpectedRecoveryIdentity, ReplicationConfig, SslMode, TlsConfig};
94pub use error::{PgWireError, Result};
95pub use lsn::Lsn;