File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 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();
You can’t perform that action at this time.
0 commit comments