I'm using LISTEN to be notified of changes. It used to work perfectly when I was listening to a DB on localhost. However, now that I've moved the DB over to another VM, I'm encountering some problems where my client loses "sync" with the DB and stops receiving notifications after some time (in order of minutes/hours).
I'm not using the connection pool, here's how I connect and listen to updates:
var client = new pg.Client(pgConString);
client.connect(function(err, client) {
if(err) {
throw err;
}
client.on('notification', function(msg) {
console.log(msg.payload);
});
client.on('error', function(error) {
console.error('This never even runs:', error);
});
var query = client.query("LISTEN watchers");
});
Is it possible keep this listener working indefinitely? Am I doing something silly? What is supposed to happen after a momentary network failure? Do I have to resign to polling the DB and diffing changes?
I'm using
LISTENto be notified of changes. It used to work perfectly when I was listening to a DB onlocalhost. However, now that I've moved the DB over to another VM, I'm encountering some problems where my client loses "sync" with the DB and stops receiving notifications after some time (in order of minutes/hours).I'm not using the connection pool, here's how I connect and listen to updates:
Is it possible keep this listener working indefinitely? Am I doing something silly? What is supposed to happen after a momentary network failure? Do I have to resign to polling the DB and diffing changes?