Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a message to the topic #250

Open
rafaelvicio opened this issue Mar 13, 2019 · 0 comments
Open

Return a message to the topic #250

rafaelvicio opened this issue Mar 13, 2019 · 0 comments

Comments

@rafaelvicio
Copy link

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant