I am trying to consume kafka message from kafkajs, but not able to read the message, please can you let me know the issue. Any Idea how to resolve this?
const kafka = new Kafka({
logLevel: logLevel.INFO,
ssl: true,
brokers: ['b-1.dev-datafabric.nmz564.c20.kafka.us-east-1.amazonaws.com:9094',
'b-2.dev-datafabric.nmz564.c20.kafka.us-east-1.amazonaws.com:9094',
'b-3.dev-datafabric.nmz564.c20.kafka.us-east-1.amazonaws.com:9094'
],
clientId: 'local-client'
})
const topic = 'aws.identity.users.0'
const consumer = kafka.consumer({
groupId: 'test-group'
})
const consumedMessages = []
const run = async () => {
await consumer.connect()
await consumer.subscribe({
topic,
fromBeginning: true
})
await consumer.run({
autoCommit: false,
eachMessage: async ({
topic,
partition,
message
}) => {
`not able to get inside this`
consumedMessages.push(message);
const prefix = `${topic}[${partition} | ${message.offset}] / ${message.timestamp}`
console.log(`- ${prefix} ${message.key}#${message.value}`)
},
})
}
`how to make this code work`
app.get('/', (req, res) => {
res.send('Hello World!')
run().catch(e => console.error(`[example/consumer] ${e.message}`, e));
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}!`)
});