Skip to content

KafkaJS Listen to commit offset callback #270

Open
@IdoBenAmi

Description

@IdoBenAmi

Hi,
I'm trying to listen ti commit event. I'm using confluent cloud as the Kafka Service.

This is the code, I copied from the documentation.
I see the consumere gets the message, the autoCommit is true by default by don't see the offset_commit_cb log.

const { Kafka, ErrorCodes } = require('@confluentinc/kafka-javascript').KafkaJS;
const kafka = new Kafka({
kafkaJS: {
groupId: "idoTest",
fromBeginning: true,
brokers: [ 'CLOUD:9092' ],
ssl: true,
sasl: {
mechanism: 'plain',
username: 'USERNAME',
password: 'PASSWORD'
}},
'offset_commit_cb': (err, offsets) => {
if (err) {
console.error(Offset commit failed for offsets ${JSON.stringify(offsets)}: ${err});
} else {
console.log(Successfully committed offsets ${JSON.stringify(offsets)});
}
},
});
const consumer = kafka.consumer();
async function run() {
await consumer.connect();
await consumer.subscribe({ topic: 'testIdo-a'});
await consumer.run({
eachMessage: async ({ topic, partition, message }) => {
console.log({
topic,
partition,
offset: message.offset,
value: message.value.toString(),
});
},
});
}
run().catch(e => console.error([example/consumer] ${e.message}, e));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions