-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.ts
41 lines (33 loc) · 1.05 KB
/
app.ts
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
// tslint:disable: no-console
import { Consumer, EventType, ResponseMessage } from '../../src'
const consume = async (consumer: Consumer) => {
await consumer.connect()
// Register the event listener before calling consume
consumer.on(EventType.Response, async (message: ResponseMessage) => {
const { offset, topic, value } = message.content()
console.log('Message received !', {
Id: value.id,
jobUUID: value.jobUUID,
offset,
topic,
chain: value.chain
})
if (value.errors && value.errors.length !== 0) {
console.log('Transaction failed!', { errors: value.errors, txContext: value.txContext })
} else {
console.log('Receipt:', value.receipt)
}
// We commit every message
await message.commit()
console.log('Message committed')
})
await consumer.consume()
}
export const start = async () => {
try {
const consumer = new Consumer(['localhost:9092'], undefined, undefined, { groupId: 'example-tx' })
await consume(consumer)
} catch (error) {
console.error(error)
}
}