forked from dailydotdev/daily-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull.ts
More file actions
32 lines (31 loc) · 806 Bytes
/
pull.ts
File metadata and controls
32 lines (31 loc) · 806 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
import { PubSub } from '@google-cloud/pubsub';
import { logger } from './src/logger';
import './src/config';
import worker from './src/workers/cdc/primary';
import createOrGetConnection from './src/db';
(async () => {
const pubsub = new PubSub();
const con = await createOrGetConnection();
const sub = pubsub.subscription('api-cdc', {
flowControl: {
maxMessages: 20,
},
});
sub.on('message', async (message) => {
try {
logger.info(
{
msgId: message.id,
orderingKey: message.orderingKey,
publishTime: message.publishTime,
},
'received message',
);
await worker.handler(message, con, logger, pubsub);
message.ack();
} catch (err) {
logger.error(err);
message.nack();
}
});
})();