Skip to content

Commit 1ff0219

Browse files
author
Kibae Shin
committed
WalStream test/sample code
1 parent 1437fc3 commit 1ff0219

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/test-walstream.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const WalStream = require(__dirname + '/../lib').WalStream;
4+
5+
var lastLsn = null;
6+
7+
var walStream = new WalStream({});
8+
function proc() {
9+
walStream.getChanges('test_slot', lastLsn, {
10+
includeXids: false, //default: false
11+
includeTimestamp: false, //default: false
12+
skipEmptyXacts: true, //default: true
13+
}, function(err) {
14+
if (err) {
15+
console.log('Logical replication initialize error', err);
16+
setTimeout(proc, 1000);
17+
}
18+
});
19+
}
20+
21+
walStream.on('data', function(msg) {
22+
lastLsn = msg.lsn || lastLsn;
23+
24+
//DO SOMETHING. eg) replicate to other dbms(pgsql, mysql, ...)
25+
console.log('log recv', msg);
26+
}).on('error', function(err) {
27+
console.log('Error #2', err);
28+
setTimeout(proc, 1000);
29+
});
30+
31+
proc();
32+
33+
//If want to stop replication
34+
//walStream.stop();

0 commit comments

Comments
 (0)