Apache kafka - consumer delay option

为君一笑 提交于 2019-12-11 15:14:50

问题


I want to start a consumer in kafka for a particular topic in a small delay. In detail , I want the consumer to start consuming the messages from the topic after a particular time delay from the time of producing the messages . Can anyone say is there any property or option in kafka to enable it . Thanks in advance.


回答1:


We did the same stuff for spark-streaming. I hope, the approach can suits you also.

The idea is very simple - use Thread.sleep. When you receive new message from kafka, you can calculate how long do you need to sleep before process it.

pseudocode for idea:

message = getNextMessageFromKafka()
sleepMs = Math.max(0, currentTime - message.timestamp)
Thread.sleep(speepMs)
do processing


来源:https://stackoverflow.com/questions/46665941/apache-kafka-consumer-delay-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!