Kafka Connect、Cassandra Sink:如何指定分区键和集群键?

Kafka Connect, Cassandra Sink: How to specify the partition and clustering keys?

我浏览了 Cassandra Sink doc 但我不知道如何指定分区和集群键。

文档是这样说的:

You can configure this connector to manage the schema on the Cassandra cluster. When altering an existing table the key is ignored. This is to avoid the potential issues around changing a primary key on an existing table. The key schema is used to generate a primary key for the table when it is created.

如果是新的 table,连接器将使用密钥模式(我想是来自 KStream)来创建主键。这可能适用于分区键,但不适用于集群键。

那么我们是否被迫在 运行 流媒体应用程序之前使用正确的键创建所有 table,或者有什么方法可以调整吗?

Confluent 的连接器要求主键中的所有列都应该在主题的键中(如结构,如果我没记错的话)。这是它的局限性之一,因为它可能与您的应用程序输出不匹配。在这种情况下,您需要转换主题以满足此要求。

我建议使用 DataStax's Kafka Connector that is carefully designed to effective load of data into Cassandra/DSE. It has following features (more information is in the following blog post):

而不是 Confluent 的连接器
  • 将一个主题的数据存储到一个或多个 Cassandra 表中(以支持数据反规范化);
  • 主题中的数据到Cassandra列的映射由配置文件定义,因此您可以将消息的任何键或值映射到列中;
  • 尽可能使用未记录的批处理并且轻量级非常有效;
  • 支持 Cassandra/DSE 的不同安全功能;

从 DSE 4.8 开始,Connector 可免费用于 DSE,从 2.1 开始,Cassandra 也可免费使用。