Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用kafka节点与消费者组手动提交消息_Node.js_Apache Kafka_Kafka Consumer Api - Fatal编程技术网

Node.js 使用kafka节点与消费者组手动提交消息

Node.js 使用kafka节点与消费者组手动提交消息,node.js,apache-kafka,kafka-consumer-api,Node.js,Apache Kafka,Kafka Consumer Api,在我的消费者组中,我想在所有任务完成后手动提交消息(如将消息推入数据库)。如何禁用自动提交和手动提交消息。设置自动提交启用为false auto.commit.enable=false consumer.commitOffsets(true) 改用。它工作得很好。您可以提交如下消息 consumer.commit({ topic: data.topic, partition: data.partition, offset: data.offset + 1 }, function(err, da

在我的消费者组中,我想在所有任务完成后手动提交消息(如将消息推入数据库)。如何禁用自动提交和手动提交消息。

设置自动提交启用为false

auto.commit.enable=false
consumer.commitOffsets(true)

改用。它工作得很好。您可以提交如下消息

consumer.commit({ topic: data.topic, partition: data.partition, offset: data.offset + 1 }, function(err, data) {})
将自动提交设置为false

const kafka = require('kafka-node');

const config = require('../config');

const client = new kafka.KafkaClient({
  kafkaHost: config.kafkaHost
});

const consumer = new kafka.Consumer(client, [
  {
    topic: config.kafkaTopic
  }
], {
  autoCommit: false
});
然后手动提交-

consumer.on('message', (message) => {
  console.log('message', message);
  // feed data into db 
  consumer.commit((error, data) => {
    if (error) {
      console.error(error);
    } else {
      console.log('Commit success: ', data);
    }
  });
});

如何使用node.js中的consumer group(使用kafka节点库)。我也做了同样的事情,但仍然得到了已经阅读的消息。