【发布时间】:2019-01-28 06:45:04
【问题描述】:
我使用Kafka流来处理实时数据,我需要对窗口时间的数据进行一些聚合操作。
我有两个关于聚合操作的问题。
- 如何获取汇总数据?我需要将它发送到第三个服务。
- 聚合操作后,我无法向第三个服务发送消息,代码无法运行。
这是我的代码:
stream = builder.stream("topic");
windowedKStream = stream.map(XXXXX).groupByKey().windowedBy("5mins");
ktable = windowedKStream.aggregate(()->"", new Aggregator(K,V,result));
// my data is stored in 'result' variable, but I can't get it at the end of the 5 mins window.
// I need to send the 'result' to a 3rd service. But I don't know where to temporarily store it and then how to get it.
// below is the code the call a 3rd service, but the code can't be executed(reachable).
// I think it should be executed every 5 mins when thewindows is over. But it isn't.
result = httpclient.execute('result');
【问题讨论】:
-
“我的数据存储在‘结果’变量中”是什么意思?另请注意,Kafka Streams 窗口聚合为窗口的每个 update 发出一个结果记录——没有最终结果的概念。 Cf:confluent.io/blog/watermarks-tables-event-time-dataflow-model——还有几个关于“最终结果”的问题,您可能想看看。
-
@MatthiasJ.Sax 对不起,'result' 是 Aggregator() 函数的第三个参数。
-
这不是 Kafka Streams 的工作方式...希望我的回答对您有所帮助。
标签: apache-kafka apache-kafka-streams