我有一个处理PostgreSQL数据库的Rust进程。此进程与服务器进程通信,以使用MPSC通道传递详细信息。我被困在如何监听和处理表修改的事件上。
我试过使用tokio-postgres,但似乎在Windows上有an issue。
发布于 2019-06-26 17:28:03
在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!!!")
}
}https://stackoverflow.com/questions/56747634
复制相似问题