简体   繁体   English

如何在Kafka或KSQL中修改或添加topic的key

[英]How to modify or add a key of topic in Kafka or KSQL

I have a lot of topics created without a key, how i can modify them and add the proper one?我创建了很多没有密钥的主题,如何修改它们并添加正确的主题?

I need change this for some connectors that want them to read topic properly我需要为一些希望他们正确阅读主题的连接器更改此设置

I personally use ksql but i didn't find any way to do it我个人使用 ksql 但我没有找到任何方法来做到这一点

Keys are added to records, not topics.键被添加到记录,而不是主题。 You can simply start writing your records with keys.您可以简单地开始使用密钥编写记录。

You can't add keys to already published records, since Kafka logs are immutable.您不能向已发布的记录添加密钥,因为 Kafka 日志是不可变的。 In order to do this you can consume data from the topic containing the unkeyed records, and set a key in each record and re-publish them to another topic.为此,您可以使用包含未键控记录的主题中的数据,并在每条记录中设置一个键并将它们重新发布到另一个主题。

You can accomplish this with KSQL using the PARTITION BY statement :您可以使用PARTITION BY 语句通过 KSQL 完成此操作:

CREATE STREAM KEYED_STREAM as \
  SELECT * FROM UNKEYED_STREAM PARTITION BY <key column>;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM