英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论