-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-consumer.js
53 lines (43 loc) · 1.18 KB
/
example-consumer.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var pgq = require('./index.js'),
config = {
consumerName: 'example_consumer',
source: {
database: 'postgres://dev:dev@localhost:5432/wtaibu_monitooring',
//database: 'postgres://[email protected]:32768/postgres',
queue: 'table.changes'
},
logDebug: true
},
consumer,
pgqSetup,
ticker;
pgqSetup = pgq.Setup(config.source.database);
pgqSetup.on('log', function(msg) {
console.log('SETUP: '+msg);
});
pgqSetup.watchTables('cloudplay.playlists', config.source.queue, function(err) {
if (err) {
console.log('failed to set up watched tables');
console.log(err);
process.exit(1);
}
consumer = new pgq.Consumer(config);
consumer.connect();
consumer.on('event', function(ev) {
console.log('CONSUMER: received event with id :'+ev.id);
console.log(ev);
ev.tagDone();
});
consumer.on('error', function(err) {
console.log('CONSUMER: got error');
console.log(err);
});
consumer.on('connected', function() {
console.log('CONSUMER: connected');
});
consumer.on('log', function(msg) {
console.log('CONSUMER: '+msg);
});
ticker = pgq.Ticker({database: config.source.database});
ticker.start();
});