Kafka sink connector : How to get Kafka message key into document


how to make use of the kafka message key? Example:

kafka message key:


kafka message value:


desired document in mongodb:

  "id": "foo",
  "payload": "bar"

I can use HoistField transformation to wrap these strings in 2 seperate json, but how to merge them to get the desired doc?

Many Thanks!

Maybe two SMTs? I bit of a guess here but something like this?

“transforms”: “HoistKey,HoistField”,
“transforms.HoistField.type”: “org.apache.kafka.connect.transforms.HoistField$Value”,
“transforms.HoistField.field”: “id”,
“transforms.HoistKey.type”: “org.apache.kafka.connect.transforms.HoistField$Key”,
“transforms.HoistKey.field”: “payload”,