forked from brianc/node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-walstream.js
More file actions
34 lines (27 loc) · 793 Bytes
/
Copy pathtest-walstream.js
File metadata and controls
34 lines (27 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const WalStream = require(__dirname + '/../lib').WalStream;
var lastLsn = null;
var walStream = new WalStream({});
function proc() {
walStream.getChanges('test_slot', lastLsn, {
includeXids: false, //default: false
includeTimestamp: false, //default: false
skipEmptyXacts: true, //default: true
}, function(err) {
if (err) {
console.log('Logical replication initialize error', err);
setTimeout(proc, 1000);
}
});
}
walStream.on('data', function(msg) {
lastLsn = msg.lsn || lastLsn;
//DO SOMETHING. eg) replicate to other dbms(pgsql, mysql, ...)
console.log('log recv', msg);
}).on('error', function(err) {
console.log('Error #2', err);
setTimeout(proc, 1000);
});
proc();
//If want to stop replication
//walStream.stop();