如何在主题上存储数据,这些数据将作为消息通过生产者传递,以便它可以加载到相应列上的数据库

How to store data on topic which will be passed as a message through producer, such that it can loaded to database on respective columns

到目前为止,我已经按照 this blog 使用 kafka spring 生成了一条关于主题的消息。

我要传递的消息只是名称,现在我想通过这个主题流式传输并添加增量值作为 ID 和名称并将其存储在 OutputTopic 上,现在,我会喜欢将数据存储到cassandra。

我的table在cassandra中的结构如下:-

CREATE TABLE emp(
   emp_id int PRIMARY KEY,
   emp_name text,
   )

输出主题上的数据应采用哪种格式,以便我可以轻松地将其存储在 cassandra 上table?

如何实现上述功能?

在 Kafka 主题上发布数据后,您可以使用 DataStax Kafka connector for Apache Cassandra, DataStax Enterprise and Astra DB

该连接器可让您将 Kafka 主题中的记录保存到 Cassandra tables。它是开源的,因此可以免费使用。

有一个 working example here,其中包括一个 Cassandra table 架构,详细介绍了如何配置 Kafka 接收器连接器以及将主题映射到 CQL table。干杯!