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.

Handle when the consumer `.eachMessage` failed `rertries`

See original GitHub issue

I want to implement my own DLQ(Dead Letter Queue). When retries=5, the consumer retry .eachMessage function 5 times and restart if the message handler throws the error.

I want to implement my own handler by catching NumberOfRetriesExceed event. My own handler will have a logic that produces a message to a specific topic and commits the offset instead of restarting the Kafka client.

How can I catch the event?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Nevoncommented, Jul 26, 2021

when eachMessage is called with a message, can we assume there are no network errors or partial data up until that point?

You cannot get partial data in your callbacks. However, your question is unrelated to this thread. Github Issues is not the place for support. Try StackOverflow or the Slack community in the future.

2reactions
Nevoncommented, Mar 13, 2019

I understand where the confusion is coming from. KafkaJS does not retry any error that is thrown from within your message processing - only errors that happen internally to KafkaJS. If your eachMessage throws because you have some issue inside it, that does not get retried by KafkaJS.

You can try it yourself quite easily:

await consumer.run({
    eachMessage: async ({ topic, partition, message }) => {
        throw new Error('💣')
    },
})

If you run that, you’ll see an error message saying: Error when calling eachMessage, along with the topic, partition and offset, but it won’t do any retries. It will just crash and restart the consumer.

If you want to retry your own message processing before giving up and sending the message to your DLQ, you’ll have to build that yourself within your eachMessage handler. We don’t export the retry functionality, so you’ll have to do it yourself though. This seems like a reasonable approach if you don’t want to roll your own.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kafka Consumer Error Handling, Retry, and Recovery
This blog post is about Kafka's consumer resiliency when we are working with apache Kafka and spring boot.
Read more >
How can I retry failure messages from kafka? - Stack Overflow
If you want at-least once guarantee, a general pattern is as follows: Disable auto commit (set enable.auto.commit to false); Consume ...
Read more >
Retrying consumer architecture in the Apache Kafka
Processing failed messages can be achieved by cloning the message and republishing it to one of retry topics with updated information about attempt...
Read more >
Kafka retries and maintaining the order of retry events - Medium
If the first attempt at first retry consumer fails, it will send the event to the next retry topic and continue processing other...
Read more >
Consuming Messages - KafkaJS
When a consumer fails the load is automatically distributed to other members ... KafkaJS offers you two ways to process your data: eachMessage...
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