How to handle unconsumed message in kafka without using the DLQ

huangapple go评论73阅读模式
英文:

How to handle unconsumed message in kafka without using the DLQ

问题

我正在使用Kafka发送消息到特定主题,并使用特定的消费者监听这些消息。在消费者内部,调用一个外部API来负责消费这些消息。我想要处理未消费的消息,如果API出现故障或失败,而不停止和重新启动消费者应用程序。我该如何处理这种情况?

英文:

I am producing messages using kafka to the particular topic, and listening the messages using particular consumer. Inside the consumer, calling an external api that is responsible to consumed the messages.

I want to handle unconsumed messages, if the api is down or fail without stopping and restarting the consumer application. How can i do this ?

答案1

得分: 0

你需要一个电路断路器,在这种情况下调用消费者实例上的暂停/关闭操作。

然后,还需要一个后台线程来定期检查你的服务,以便重新启动消费者。

Kafka 没有内置的实用工具来执行这些操作。

否则,让消费者失败。禁用自动提交,数据仍将保留在主题中。然而,你仍需要进行暂停/关闭操作,以避免在消费者运行时出现无尽的异常。

附注:在这种情况下,最好使用Kafka Connect框架,因为它具有内置的容错特性。

英文:

You need a circuit breaker that calls pause/close on the consumer instance in that scenario.

Then some background thread to ping your service, and restart the consumer again.

Kafka doesn't come with any utilities to do this for you.

Otherwise, let the consumer fail. Disable auto commits, and data will still remain retained in the topic. However, you'll still need to pause/close to not get endless exceptions while the consumer is running.

Sidenote: Kafka Connect framework should ideally be used here instead, as it has builtin fault tolerance features

huangapple
  • 本文由 发表于 2023年4月11日 14:40:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983044.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定