Skip to content

Instantly share code, notes, and snippets.

@zikani03
Created April 22, 2017 11:37
Show Gist options
  • Save zikani03/e4fa4f150940dbdb03a6761fd0c41995 to your computer and use it in GitHub Desktop.
Save zikani03/e4fa4f150940dbdb03a6761fd0c41995 to your computer and use it in GitHub Desktop.
Rust + Node via Postgres notify/listen
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);
})
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