我有一个处理PostgreSQL数据库的Rust进程。此过程与服务器过程进行通信,以使用MPSC通道传递详细信息。我被困在如何监听和处理表修改事件上。
我尝试使用tokio-postgres,但Windows上似乎有an issue。
答案 0 :(得分:0)
收听PostgreSQL特定频道上的事件如下:-
// Establish connection with database.
let url = "postgresql://root:root1234@127.0.01/test";
let conn = Connection::connect(url, TlsMode::None).unwrap();
// Listen for events on channel 'myevent'.
conn.execute("LISTEN myevent", &[]).expect("Could not send LISTEN");
let notifications = conn.notifications();
let mut it = notifications.blocking_iter();
println!("Waiting for notifications...");
loop {
let a = it.next();
match a {
Ok(Some(b)) => {
println!("{:?}", b);
},
Err(e) => println!("Got error {:?}", e),
_ => panic!("Unexpected operation!!!")
}
}