您现在的位置是:首页 > 电脑 > 

Kafka:阻止读取但不轮询的Java客户端(Kafka: Java client that blocks read and doesn't poll)

2025-07-29 02:43:09
Kafka:阻止读取但不轮询的Java客户端(Kafka: Java client that blocks read and doesn't poll) 我想知道是否有一个Kafka Cumer的Java客户端代码能够通过推送通知/阻塞读取而不是当前轮询来读取数据: final KafkaCumer<String, String>
Kafka:阻止读取但不轮询的Java客户端(Kafka: Java client that blocks read and doesn't poll)

我想知道是否有一个Kafka Cumer的Java客户端代码能够通过推送通知/阻塞读取而不是当前轮询来读取数据:

final KafkaCumer<String, String> cumer = new KafkaCumer<String, String>(props); cumer.subscribe(Arrays.asList("test")); new Thread(){ @Override public void run() { while (true) { CumerRecords<String, String> records = cumer.poll(100); //poll for (CumerRecord<String, String> record : records) { printf("offset = %d, key = %s, value = %s", (), record.key(), record.value()); println(); (record.value()); } } } }.start();

I was wondering if there is a java client code that is a Kafka Cumer that enables to read data via push notification / a blocking read, instead of the current poll:

final KafkaCumer<String, String> cumer = new KafkaCumer<String, String>(props); cumer.subscribe(Arrays.asList("test")); new Thread(){ @Override public void run() { while (true) { CumerRecords<String, String> records = cumer.poll(100); //poll for (CumerRecord<String, String> record : records) { printf("offset = %d, key = %s, value = %s", (), record.key(), record.value()); println(); (record.value()); } } } }.start();

最满意答案

如果我正确理解你的问题,你希望数据在可用时被推送到消费者,而不是让消费者负责检查新数据和拉动。

在https://kafka./08/design.html他们讨论了推送与拉动以及在Kafka中做出的选择,其中生产者将消息推送到代理并且消费者从经纪人处获取。 他们还提到了他们为防止基于拉动的方法的缺点所做的尝试。 如果您需要推送发布/订阅消息系统,您可能需要查看链接中提到的Scribe或Flume :)

if I understand your question correctly you wish for the data to be pushed to cumer when available instead of having the cumer being respible of checking from new data and pulling.

On https://kafka./08/design.html they discuss push vs. pull and the choice that was made in Kafka where the producer push the messages to the broker and the cumer pulls from broker. They also mention the attempts they have made to prevent the downsides of a pull-based approach. If you require a pushing pub/sub messaging system you may want to look at Scribe or Flume which is also mentioned in the link :)

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/648938.html

相关标签:无
上传时间: 2023-07-26 17:22:56
留言与评论(共有 7 条评论)
本站网友 南开二手房出售
5分钟前 发表
final KafkaCumer<String
本站网友 手机当电脑摄像头
11分钟前 发表
key = %s
本站网友 慢性气管炎食疗
22分钟前 发表
而不是让消费者负责检查新数据和拉动
本站网友 照华农庄
20分钟前 发表
instead of the current poll
本站网友 扬州二手房出售
10分钟前 发表
String> record
本站网友 董慧图片
26分钟前 发表
String> record