Handle when the consumer `.eachMessage` failed `rertries`
See original GitHub issueI 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:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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:
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.