Flink流根据条件进入两个接收器

发布于 2025-01-21 02:40:42 字数 280 浏览 3 评论 0原文

试图根据条件看到流到两个水槽的可能性。

Requirement is stream have events, all events after transformation need to go to one sink ( assume one kafka topic)

And only error events needs to go to another sink ( assume another kafka topic).

一旦完成转换的用例,都没有将其他逻辑放入水槽中。看是否做类似的事情

Trying to see the possibility of stream going to two sinks based on conditions.

Requirement is stream have events, all events after transformation need to go to one sink ( assume one kafka topic)

And only error events needs to go to another sink ( assume another kafka topic).

did not see use-case of once transformation is done , additional logic putting in sink. Looking if something similar done

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2025-01-28 02:40:42

最好的方法是使用

private static final OutputTag<String> errors = new OutputTag<>("errors") {};

...

// in your main() method
SingleOutputStreamOperator<T> result = events.process(new ProcessFunction());

result.addSink(sink).name("normal output");
result.getSideOutput(errors).addSink(errorSink).name("error output");

...

// in the process function

if (somethingGoesWrong) {
    ctx.output(errors, "error message");
}

虽然还有其他方法可以将流动的流链分开,但侧输出非常灵活(例如,侧输出可以具有不同的类型)并且表现良好。

The best way to do this is with side outputs.

private static final OutputTag<String> errors = new OutputTag<>("errors") {};

...

// in your main() method
SingleOutputStreamOperator<T> result = events.process(new ProcessFunction());

result.addSink(sink).name("normal output");
result.getSideOutput(errors).addSink(errorSink).name("error output");

...

// in the process function

if (somethingGoesWrong) {
    ctx.output(errors, "error message");
}

While there are other ways to split a stream with Flink, side outputs are very flexible (e.g., the side outputs can have different types) and perform well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文