简体   繁体   中英

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

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. 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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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