Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use message key in Kafka connect source connector

I'm using the Kafka connect JDBC source connector to read from a view in a database and post it on kafka, it is working fine.

My use case is that a user can create multiple objects and the order of the objects is important in my application. I would like to use the user id as the message key of all the messages I'm posting into the topic to maintain their order.

My question is how can I define a message key in the Kafka connect source connector?

like image 290
Alejandro Agapito Bautista Avatar asked Jun 21 '18 22:06

Alejandro Agapito Bautista


1 Answers

You can use Kafka Connect's SMT (Single Message Transforms) feature by adding following code to connect-file-source configuration file.

transforms=createKey
transforms.createKey.type=org.apache.kafka.connect.transforms.ValueToKey
transforms.createKey.fields=UserId <name of user id column>

More information about SMT here

like image 56
Quang Vien Avatar answered Nov 15 '22 07:11

Quang Vien