corebasic 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/kafka.js +6 -2
- package/package.json +1 -1
package/libs/kafka.js
CHANGED
|
@@ -46,13 +46,17 @@ const start_consumer = async function (topic, groupId, callback) {
|
|
|
46
46
|
await consumer.subscribe({ topic: topic, fromBeginning: true })
|
|
47
47
|
|
|
48
48
|
await consumer.run({
|
|
49
|
+
autoCommit: false,
|
|
49
50
|
eachMessage: async ({ topic, partition, message }) => {
|
|
50
51
|
// callback(topic, message.value.toString(), partition) // toString() returns array so won't parse if json.
|
|
52
|
+
let success
|
|
51
53
|
try {
|
|
52
|
-
callback(topic, JSON.parse(message.value), partition)
|
|
54
|
+
success = callback(topic, JSON.parse(message.value), partition)
|
|
53
55
|
} catch (ex) {
|
|
54
|
-
callback(topic, message.value, partition)
|
|
56
|
+
success = callback(topic, message.value, partition)
|
|
55
57
|
}
|
|
58
|
+
|
|
59
|
+
await consumer.commitOffsets([{ topic, partition, offset: (Number(message.offset) + 1).toString() }]);
|
|
56
60
|
},
|
|
57
61
|
})
|
|
58
62
|
}
|