|
14 | 14 | //!
|
15 | 15 | //! # Physical Replication Client Example
|
16 | 16 | //! ```no_run
|
17 |
| -//! extern crate tokio; |
18 |
| -//! |
19 | 17 | //! use postgres_protocol::message::backend::ReplicationMessage;
|
20 |
| -//! use tokio::stream::StreamExt; |
| 18 | +//! use futures::StreamExt; |
21 | 19 | //! use tokio_postgres::{connect_replication, Error, NoTls, ReplicationMode};
|
22 | 20 | //!
|
23 | 21 | //! #[tokio::main]
|
|
61 | 59 | //! extension](https://github.com/eulerto/wal2json).
|
62 | 60 | //!
|
63 | 61 | //! ```no_run
|
64 |
| -//! extern crate tokio; |
65 |
| -//! |
66 | 62 | //! use postgres_protocol::message::backend::ReplicationMessage;
|
67 |
| -//! use tokio::stream::StreamExt; |
| 63 | +//! use futures::StreamExt; |
68 | 64 | //! use tokio_postgres::{connect_replication, Error, NoTls, ReplicationMode};
|
| 65 | +//! use postgres_protocol::replication::pgoutput::{PgOutput, LogicalReplicationMessage}; |
69 | 66 | //!
|
70 | 67 | //! #[tokio::main]
|
71 | 68 | //! async fn main() -> Result<(), Error> {
|
|
85 | 82 | //! let identify_system = rclient.identify_system().await?;
|
86 | 83 | //!
|
87 | 84 | //! let slot = "my_slot";
|
88 |
| -//! let plugin = "wal2json"; |
89 |
| -//! let options = &vec![("pretty-print", "1")]; |
| 85 | +//! let plugin = PgOutput::new(vec!["publication_name".to_string()]); |
90 | 86 | //!
|
91 | 87 | //! let _slotdesc = rclient
|
92 |
| -//! .create_logical_replication_slot(slot, false, plugin, None) |
| 88 | +//! .create_logical_replication_slot(slot, false, &plugin, None) |
93 | 89 | //! .await?;
|
94 | 90 | //!
|
95 |
| -//! let mut physical_stream = rclient |
96 |
| -//! .start_logical_replication(slot, identify_system.xlogpos(), options) |
| 91 | +//! let mut logical_stream = rclient |
| 92 | +//! .start_logical_replication(slot, identify_system.xlogpos(), &plugin) |
97 | 93 | //! .await?;
|
98 | 94 | //!
|
99 |
| -//! while let Some(replication_message) = physical_stream.next().await { |
| 95 | +//! while let Some(replication_message) = logical_stream.next().await { |
100 | 96 | //! match replication_message? {
|
101 | 97 | //! ReplicationMessage::XLogData(xlog_data) => {
|
| 98 | +//! use LogicalReplicationMessage::*; |
102 | 99 | //! eprintln!("received XLogData: {:#?}", xlog_data);
|
103 |
| -//! let json = std::str::from_utf8(xlog_data.data()).unwrap(); |
104 |
| -//! eprintln!("JSON text: {}", json); |
| 100 | +//! match xlog_data.data() { |
| 101 | +//! Insert(insert) => eprintln!("insert event: {:?}", insert), |
| 102 | +//! Update(update) => eprintln!("update event: {:?}", update), |
| 103 | +//! Delete(delete) => eprintln!("delete event: {:?}", delete), |
| 104 | +//! event => eprintln!("other {:?}", event), |
| 105 | +//! } |
105 | 106 | //! }
|
106 | 107 | //! ReplicationMessage::PrimaryKeepAlive(keepalive) => {
|
107 | 108 | //! eprintln!("received PrimaryKeepAlive: {:#?}", keepalive);
|
@@ -739,7 +740,7 @@ impl ReplicationClient {
|
739 | 740 | /// and data messages will be in
|
740 | 741 | /// [CopyData](postgres_protocol::message::backend::Message::CopyData).
|
741 | 742 | ///
|
742 |
| -/// Intended to be used with the [next()](tokio::stream::StreamExt::next) method. |
| 743 | +/// Intended to be used with the [next()](futures::StreamExt::next) method. |
743 | 744 | ///
|
744 | 745 | /// If the timeline specified with
|
745 | 746 | /// [start_physical_replication()](ReplicationClient::start_physical_replication)
|
|
0 commit comments