如何处理kafka KStream并直接写入数据库,而不是将其发送给另一个主题 [英] How to Process a kafka KStream and write to database directly instead of sending it another topic

查看:538
本文介绍了如何处理kafka KStream并直接写入数据库,而不是将其发送给另一个主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想将处理后的KStream写入另一个主题,我直接想将丰富的KStream写入数据库.我应该如何进行?

I don't want to write processed KStream to another topic, I directly want to write enriched KStream to database. How should I proceed?

推荐答案

您可以实现自定义Processor,该自定义Processor打开DB连接并通过KStream#process()应用它. cf. https://docs.confluent.io/current/streams/developer-guide/dsl-api.html#applying-processors-and-transformers-processor-api-integration

You can implement a custom Processor that opens a DB connection and apply it via KStream#process(). Cf. https://docs.confluent.io/current/streams/developer-guide/dsl-api.html#applying-processors-and-transformers-processor-api-integration

请注意,您需要对数据库进行同步写入,以防止数据丢失.

因此,不回写主题有多个缺点:

Thus, not writing back to a topic has multiple disadvantages:

  • 由于同步写入,导致吞吐量降低
  • 您不能使用一次精确的语义
  • 将您的应用程序与数据库耦合(如果数据库出现故障,您的应用程序也会发生故障,因为它无法再写入结果了)

因此,建议将结果写回到主题中,并使用Connect API将数据获取到数据库中.

这篇关于如何处理kafka KStream并直接写入数据库,而不是将其发送给另一个主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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