简体   繁体   English

Kafka Java使用者

[英]Kafka Java Consumer

My Kafka consumer has 2 threads and the number of partitions is let's say 10 so overall 5 partitions per consumer thread. 我的Kafka使用者有2个线程,分区的数量为10个,因此每个使用者线程总共有5个分区。 I am saving the time at which a particular record needs to be processed. 我节省了需要处理特定记录的时间。 Now if record1 on partition1 needs to be picked 10 hours from now Thread should move to next partition to see if next partition can be picked. 现在,如果需要从现在开始的10小时内选择partition1上的record1,则线程应移至下一个分区,以查看是否可以选择下一个分区。

example : 例如:

P1 - 8
P2 - 7
P3 - 6
P4 - 5
P5 - 4

Now data on partition P1 needs to be picked at 8 hours and the current time is 6 hours if I make my thread to wait for 8 hours I'll wait for 1 hour although I could process P3, P4, and P5. 现在,需要在8小时时选择分区P1上的数据,如果我让线程等待8小时,则当前时间是6小时,尽管可以处理P3,P4和P5,但我将等待1小时。

Please let me know how should I proceed. 请让我知道我应该如何进行。

I would go easier way: have consumer per partition. 我会更简单的方法:每个分区都有消费者。 There is KafkaConsumer.assign() API to really select and assign particular partition to the consumer. KafkaConsumer.assign() API可以真正选择特定的分区并将其分配给使用者。 This way each of them will deal with its own isolated logic based on the mentioned schedule. 这样,他们每个人都将根据上述时间表处理自己的隔离逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM