I have a kafka topic which is getting data from mysql database using Debezium mysql source connector, following is the format of one of the messages:
{
"Message": {
"schema": {
"type": "struct",
"fields": [
...
],
"optional": true,
"name": "mysql-server-1.inventory.somename"
},
"payload": {
"op": "u",
"ts_ms": 1465491411815,
"before": {
"id": 1004,
"first_name": "Anne",
"last_name": "Doof",
"email": "annek@noanswer.org"
},
"after": {
"id": 1004,
"first_name": "Anne",
"last_name": "Marry",
"email": "annek@noanswer.org"
},
"source": {
"db": "inventory",
"table": "customers",
...
"query": "Update customers set last_name = 'Marry' where id = 1004"
}
}
}
}
I want to push ts_ms, before, after
and id
(from the object/row) columns into another database using jdbc sink connector with table schema as (id,before(text),after(text),timestamp)
, being new to kafka cant figure out:
how can i extract these fields only, from the message to push and ignore others?
how can i transform before, after fields to string/serialize format?
how can i extract
id
from object? (incase of insert operation, before will be null, for delete, after will be null)
For the message above, the sink destination table should have data like this below at the end:
id: 1004
before: '{"id":1004,"first_name":"Anne","last_name":"Doof","email":"annek@noanswer.org"}'
after: '{"id":1004,"first_name":"Anne","last_name":"Marry","email":"annek@noanswer.org"}'
timestamp: 1465491411815