Kafka/Connect/Streams 用于数据库字段更新
Kafka/Connect/Streams for DB field update
我的问题如下:
我有 2 个 kafka 主题:
customer-purchase
:包含客户购买的信息,其中一个字段表示状态等于NEW
。
purchase-status
:包含更新购买最新状态的事件,例如IN TRANSIT
、DELIVERED
...
使用 kafka,kafka connect and/or kafka 流,我想最终得到一个 SQL 数据库,其中包含丰富的最新状态信息的购买。
在数据库世界中,这将导致一个简单的 UPDATE
查询。
理论上,我可以为 customer-purchase
编写 1 个消费者(或 1 个连接接收器),其中所有内容都简单地转储到数据库,并为 purchase-status
编写 1 个消费者,这将触发数据库 UPDATE
查询,但我想知道是否有更像 kafka 的方式来做到这一点。
注意:使用 kafka-streams 并加入 2 个主题对我来说似乎有点矫枉过正,因为我实际上不需要加入,而是一个字段的简单更新。但我的这个假设可能完全错了!
Theoretically, I could write 1 consumer (or 1 connect sink) for the customer-purchase, where everything is simply dumped to the DB and 1 consumer for the purchase-status which would trigger a DB UPDATE query, but I was wondering whether there is a more kafka-like way to do this.
这几乎就是 Kafka Streams 中的 table-table 加入的实际作用。
在您的示例中,您是通过 "one-event-at-a-time processing" 的视角来看待它的。 Table-table joins send such "updates" 与您所描述的非常相似。请参阅 https://kafka.apache.org/documentation/streams/developer-guide/dsl-api.html#ktable-ktable-join.
处的连接语义
Note: using kafka-streams and joining the 2 topics there seemed a little overkill to me since I actually don't need the join but a simple update of a field. But I might be completely wrong in this assumption!
您提到您考虑过加入这两个主题,但最终决定反对。为什么这样?这似乎是个好主意,对我来说也是惯用的。它与 DB 世界示例也没有太大区别:您将如何执行 "SQL database which contains the purchase enriched with the latest status information" 中的丰富步骤?这实际上是一个连接操作(见上文)。
我的问题如下:
我有 2 个 kafka 主题:
customer-purchase
:包含客户购买的信息,其中一个字段表示状态等于NEW
。purchase-status
:包含更新购买最新状态的事件,例如IN TRANSIT
、DELIVERED
...
使用 kafka,kafka connect and/or kafka 流,我想最终得到一个 SQL 数据库,其中包含丰富的最新状态信息的购买。
在数据库世界中,这将导致一个简单的 UPDATE
查询。
理论上,我可以为 customer-purchase
编写 1 个消费者(或 1 个连接接收器),其中所有内容都简单地转储到数据库,并为 purchase-status
编写 1 个消费者,这将触发数据库 UPDATE
查询,但我想知道是否有更像 kafka 的方式来做到这一点。
注意:使用 kafka-streams 并加入 2 个主题对我来说似乎有点矫枉过正,因为我实际上不需要加入,而是一个字段的简单更新。但我的这个假设可能完全错了!
Theoretically, I could write 1 consumer (or 1 connect sink) for the customer-purchase, where everything is simply dumped to the DB and 1 consumer for the purchase-status which would trigger a DB UPDATE query, but I was wondering whether there is a more kafka-like way to do this.
这几乎就是 Kafka Streams 中的 table-table 加入的实际作用。
在您的示例中,您是通过 "one-event-at-a-time processing" 的视角来看待它的。 Table-table joins send such "updates" 与您所描述的非常相似。请参阅 https://kafka.apache.org/documentation/streams/developer-guide/dsl-api.html#ktable-ktable-join.
处的连接语义Note: using kafka-streams and joining the 2 topics there seemed a little overkill to me since I actually don't need the join but a simple update of a field. But I might be completely wrong in this assumption!
您提到您考虑过加入这两个主题,但最终决定反对。为什么这样?这似乎是个好主意,对我来说也是惯用的。它与 DB 世界示例也没有太大区别:您将如何执行 "SQL database which contains the purchase enriched with the latest status information" 中的丰富步骤?这实际上是一个连接操作(见上文)。