Reputation: 33
I'd like to write kafka record key to PostgreSQL to separate column and this column should NOT be a primary key. How to configure my JDBC sink connector?
Example: Record in kafka topic:
Result in Database:
COL1 ; COL2 abc ; value_1 abc ; value_2
COL1 is not a primary key
Upvotes: 0
Views: 943
Reputation: 191983
In order to not write a database key, you'll need to relocate the key into the ConnectRecord value Struct.
You should be able to use a transform such as this one (admittedly, it's old and mentions S3, but should work for this purpose)
After installing into your Connect cluster classpath, and configuring in the connector, all records will be written to the database with columns key|value|topic|timestamp
. Also make sure that pk.mode=none
, and use JSONConverter with schemas enabled (or Avro / Protobuf if using Schema Registry)
You can also rename/drop columns if you don't need the topic or timestamp and explicitly want "col1", "col2"
Upvotes: 2