oleksiyk / kafka

Apache Kafka 0.9 client for Node
MIT License
297 stars 85 forks source link

Return a message to the topic #250

Open rafaelvicio opened 5 years ago

rafaelvicio commented 5 years ago

By default in no-kafka there is a tentative configuration that defaults to 3.

return producer.send(messages, {
  retries: {
    attempts: 2,
    delay: {
      min: 100,
      max: 300
    }
  }
});

How can I manually decline a message?

var consumer = new Kafka.SimpleConsumer();

// data handler function can return a Promise
var dataHandler = function(messageSet, topic, partition) {
  messageSet.forEach(function(m) {
    const random = Math.floor(Math.random() * 11);
    if (random > 5) {
      console.log(topic, partition, m.offset, m.message.value.toString("utf8"));
    } else {
        // Decline a message
      console.log("Decline a message");
    }
  });
};

return consumer.init().then(function() {
  // Subscribe partitons 0 and 1 in a topic:
  return consumer.subscribe("kafka-test-topic", [0, 1], dataHandler);
});