How to Process a kafka KStream and write to database directly instead of sending it another topic

前端 未结 1 1820
面向向阳花
面向向阳花 2021-01-13 08:31

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

相关标签:
1条回答
  • 2021-01-13 08:40

    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

    Note, you will need to do sync writes into your DB to guard against data loss.

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

    • reduced throughput because of sync writes
    • you cannot use exactly-once semantics
    • coupling your application with the database (if DB goes down, your app goes down, too, as it can't write its results anymore)

    Therefore, it's recommended to write the results back into a topic and use Connect API to get the data into your database.

    0 讨论(0)
提交回复
热议问题