Flink 什么时候使用 CoProcess 函数? [英] When to use CoProcess Function in Flink?

查看:26
本文介绍了Flink 什么时候使用 CoProcess 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想了解在 Flink 中何时使用 CoProcessFunction 的用例.举例说明有助于我更好地理解这个概念.

I am just trying to understand the use case when to use CoProcessFunction in Flink. Explanation with an example would help me to understand the concept better.

推荐答案

CoProcessFunction 类似于 RichCoFlatMap,但增加了还可以使用计时器的功能.例如,计时器可用于过期密钥的过期状态,或在保持活动消息未能到达时发出警报.

A CoProcessFunction is similar to a RichCoFlatMap, but with the addition of also being able to use timers. The timers are useful for expiring state for stale keys, or for raising alarms when keep alive messages fail to arrive, for example.

CoProcessFunction 允许您使用一个流来影响另一个流的处理方式,或丰富另一个流.例如,一个电子商务网站可能有一个订单事件流和一个发货事件流,他们希望为下订单 24 小时后尚未发货的订单创建一个事件流.这两个流可以由 orderId 键控,并连接在一起.当订单到达时,它被记录为键控状态,并创建一个计时器以在 24 小时后触发.当一个装运事件到达时,状态和计时器被清除.如果计时器触发,则使用该状态将订单发送到未完成的订单服务.

A CoProcessFunction allows you to use one stream to influence how another is processed, or to enrich another stream. For example, an e-commerce site might have a stream of order events and a stream of shipment events, and they want to create a stream of events for orders that haven't shipped with 24 hours of the order being placed. The two streams can be keyed by the orderId, and connected together. As an order arrives it's recorded in keyed state, and a timer is created to fire 24 hours later. When a shipment event arrives, the state and timer are cleared. If a timer does fire, the state is used to send the order out to the unfilled order service.

有关这方面的更多信息和代码示例,请参阅 连接流过程函数 以及这些教程附带的实验室.

For more on this, and examples with code, see connected streams and process function and the labs that accompany those tutorials.

这篇关于Flink 什么时候使用 CoProcess 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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