question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unable to consume specific amount of messages without waiting with a setTimeout

See original GitHub issue

Environment Information

  • OS [e.g. Mac, Arch, Windows 10]: RedHat
  • Node Version [e.g. 8.2.1]: 10.6.0
  • NPM Version [e.g. 5.4.2]: 6.1.0
  • C++ Toolchain [e.g. Visual Studio, llvm, g++]:
  • node-rdkafka version [e.g. 2.3.3]: 2.3.2
// Non-flowing mode
consumer.connect();

consumer
  .on('ready', function() {
    consumer.subscribe(['librdtesting-01']);

    // Read only 1000 messages
    consumer.consume(1000); // <---------- This is not working...
  })
  .on('data', function(data) {
    console.log('Message found!  Contents below.');
    console.log(data.value.toString());
  });

If i’m replacing the line that I’ve marked above with the following, then it does work:

setTimeout(() => consumer.consume(1000), 60000); // <-- this is working..

Could this be related to node-rdkafka? or is it something that has to do with my kafka configuration?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
rosshaddencommented, Mar 18, 2019

Multiple people have the same problem (myself included). This should not be closed.

2reactions
thebigredgeekcommented, Oct 8, 2018

Is there not an error event emitted? I am seeing something very similar, but error is null and the messages array is empty. It seems like ready is being fired before the consumer has fetched partition offsets, according to the logs when i set debug to `consumer. Also, it appears that the offset is being incremented even though I am not receiving the messages through the data or consume callbacks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is setTimeout with no delay the same as executing the function ...
The reason is that setTimeout removes the function from the execution queue ... The time, in milliseconds that the timer should wait before...
Read more >
setTimeout() - Web APIs | MDN
The global setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires.
Read more >
setTimeout not triggering when unit testing #3211 - GitHub
It won't log the message, because Jest buffers all console calls so they can be displayed after test results reporters, and since setTimeout() ......
Read more >
Scheduling: setTimeout and setInterval
To cancel the execution, we should call clearTimeout/clearInterval with the value returned by setTimeout/setInterval .
Read more >
Using setTimeout in React components (including hooks)
Can't call "this.setState" on an unmounted component. To clear a timeout, we need to call clearTimeout with the returned value of setTimeout :....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found