SetSchemaMetadata for both key and value

Viewed 529

I am using the Kafka Connect JDBC Source Connector to stream data from a Postgres Database to Kafka. All messages in the kafka cluster are Avro messages managed by the Schema Registry. I want to set explicitly the schema name for both the key and value of the messages.

I managed to do it for either the key or the value by using the SetSchemaMetadata option on the config.

For setting the schema name for the value, I am using:

"transforms": "SetSchemaMetadata",
"transforms.SetSchemaMetadata.type": 
"org.apache.kafka.connect.transforms.SetSchemaMetadata$Value",
"transforms.SetSchemaMetadata.schema.name": "myCustomValueSchemaName"

For the key, I am using :

"transforms": "SetSchemaMetadata",
"transforms.SetSchemaMetadata.type": 
"org.apache.kafka.connect.transforms.SetSchemaMetadata$Key",
"transforms.SetSchemaMetadata.schema.name": "myCustomKeySchemaName"

Is there a way to set both of them on the connect config ?

Many thanks

1 Answers

I think you can use chained tranformation:

"transforms": "KeySchemaMetadata,ValueSchemaMetadata",

"transforms.KeySchemaMetadata.type": "org.apache.kafka.connect.transforms.SetSchemaMetadata$Key",
"transforms.KeySchemaMetadata.schema.name": "myCustomKeySchemaName",

"transforms.ValueSchemaMetadata.type": "org.apache.kafka.connect.transforms.SetSchemaMetadata$Value",
"transforms.ValueSchemaMetadata.schema.name": "myCustomValueSchemaName"
Related