Created
August 9, 2020 15:31
-
-
Save thakursaurabh1998/7bc9306ca1ed15ec03b6f630032f7ca0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const async = require('async'); | |
const { ConsumerGroup } = require('kafka-node'); | |
const consumerConfig = { | |
kafkaHost: 'broker:9092', | |
groupId: 'order-service', | |
fetchMaxBytes: 100 * 1024, // 100 KB | |
autoCommit: false, | |
}; | |
const consumer = new ConsumerGroup(consumerConfig, 'OrderTopic'); | |
async function processData(queueData) { | |
// perform data processing here | |
} | |
const concurrency = 5; | |
const q = async.queue(processData, concurrency); | |
q.drain(() => { | |
consumer.commit(); | |
consumer.resume(); | |
}); | |
consumer.on('message', (data) => { | |
consumer.pause(); | |
q.push(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment