Apache Kafka-消费者延迟选项 [英] Apache kafka - consumer delay option

查看:614
本文介绍了Apache Kafka-消费者延迟选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想花一点时间在kafka中启动某个特定主题的消费者.详细地讲,我希望使用者在产生消息的特定时间延迟后开始使用主题中的消息.任何人都可以说kafka中有任何属性或选项可以启用它.预先感谢.

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.

推荐答案

我们在火花流处理方面做了同样的事情.我希望这种方法也适合您.

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

这个想法很简单-使用Thread.sleep.当您收到来自kafka的新消息时,可以计算出处理该消息之前需要休眠多长时间.

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.

想法的伪代码:

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

这篇关于Apache Kafka-消费者延迟选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆