KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have an "article" table on a Postgresql 9.1 database and a trigger that notifies a channel on each insert. I'd like to create a node.js script that catches those inserts and pushes notifications to connected clients using Socket.io. So far I'm using the node-postgres module to LISTEN to the channel but it seems the LISTEN query times out after about 10-15 seconds and stops catching the inserts. I could query a new listen when the timeout happens, but I'm not sure how to properly implement the continuation. Here's my postgresql notification procedure: CREATE FUNCTION article_insert_notify() RETURNS trigger AS $$ BEGIN NOTIFY "article_watcher"; RETURN NULL; END; $$ LANGUAGE plpgsql; The trigger: CREATE TRIGGER article_insert_trigger AFTER INSERT ON article FOR EACH ROW EXECUTE PROCEDURE article_insert_notify(); And the node.js code: var pg = require ('pg'), pgConnection = "postgres://user:pass@localhost/db" pg.connect(pgConnection, function(err, client) { client.query('LISTEN "article_watcher"'); client.on('notification', function(data) { console.log(data.payload); }); }); How can I ensure a fulltime LISTEN or how could I catch those timeouts to reissue a listen query ? Or maybe a module other than node-postgres offers more appropriate tools to do so ?
Tags (comma-separated)
Save Edits
Cancel