Setting the key of a Kafka message is important as it ensures correct logical processing when consumed across multiple partitions, as well as being a requirement when joining to messages in other topics. When using Kafka Connect the connector may already set the key, which is great. If not, you can use these two Single Message Transforms (SMT) to set it as part of the pipeline based on a field in the value part of the message.
To use the ValueToKey Single Message Transform specify the name of the field (id ) that you want to copy from the value to the key:
" transforms " : " copyIdToKey " ,
" transforms.copyIdToKey.type " : " org.apache.kafka.connect.transforms.ValueToKey " ,
" transforms.copyIdToKey.fields " : " id " ,