Created
April 22, 2017 11:37
-
-
Save zikani03/e4fa4f150940dbdb03a6761fd0c41995 to your computer and use it in GitHub Desktop.
Rust + Node via Postgres notify/listen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pg = require('pg'); | |
var client = new pg.Client('postgresql://username:password@localhost:5432/labs'); | |
client.connect(); | |
client.query('LISTEN events', function(err, msg) { | |
if (err) throw err; | |
}); | |
client.on('notification', function(msg) { | |
var event = msg.payload; | |
console.log("Got event: " + event); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate postgres; | |
use postgres::{Connection, TlsMode}; | |
fn main() { | |
println!("Sending events to node via Postgres NOTIFY/LISTEN. neat!"); | |
let connection = Connection::connect("postgresql://username:password@localhost:5432/labs", TlsMode::None).unwrap(); | |
connection.execute("NOTIFY events, 'hello node!';", &[]).unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment