I need help to achieve few things. I have created a data pipeline as mentioned below.
Mysql-->debezium--> Kafka-->Kafka Connect--->AWS S3.
Now S3 will have a debezium event message in JSON format.
Now need to load this to Redshift as a table.
S3-->Redshift(Target Database) as rows.
Below I have shared a debezium event message for an single update event(Updated quantity of an product_id 102) and just want to have in a format which when I do copy command in S3, it should load the changes(Create/Update/Delete) into redshift table.
Note: here I have given "rotate.interval.ms": "3600000" for each our a debezium message file will be created which will have all CRUD actions.
So need a solution such that it transforms each newly created file in S3 which as debezium message events to a format where we can apply a copy command such that it loads in redshift. MY Main goal is to capture CDC Changes from MYSQL and replicate in Redshift.
This is my S3 sink Connector config: Kafka Connect S3 Sink:
{
"name": "s3-sink-db02",
"config": {
"connector.class": "io.confluent.connect.s3.S3SinkConnector",
"storage.class": "io.confluent.connect.s3.storage.S3Storage",
"s3.bucket.name": "S3bucket",
"name": "s3-sink-db02",
"tasks.max": "3",
"s3.region": "us-east-1",
"aws.access_key_id": "accesskey",
"aws.secret_access_key": "secretKey",
"s3.part.size": "5242880",
"s3.compression.type": "gzip",
"timezone": "UTC",
"locale": "en",
"flush.size": "10000",
"rotate.interval.ms": "3600000",
"topics.regex": "dbserver1.(.*)",
"internal.key.converter.schemas.enable": "false",
"key.converter.schemas.enable": "false",
"internal.key.converter": "org.apache.kafka.connect.json.JsonConverter",
"format.class": "io.confluent.connect.s3.format.json.JsonFormat",
"internal.value.converter.schemas.enable": "false",
"value.converter.schemas.enable": "false",
"internal.value.converter": "org.apache.kafka.connect.json.JsonConverter",
"value.converter": "org.apache.kafka.connect.json.JsonConverter",
"key.converter": "org.apache.kafka.connect.json.JsonConverter",
"partitioner.class": "io.confluent.connect.storage.partitioner.HourlyPartitioner",
"path.format": "YYYY/MM/dd/HH",
"partition.duration.ms": "3600000",
"rotate.schedule.interval.ms": "3600000"
}
}
Debezium Message:
{
"schema": {
"name": "dbserver1.inventory.orders.Envelope",
"optional": false,
"type": "struct",
"fields": [
{
"field": "before",
"name": "dbserver1.inventory.orders.Value",
"optional": true,
"type": "struct",
"fields": [
{
"field": "order_number",
"optional": false,
"type": "int32"
},
{
"field": "order_date",
"name": "io.debezium.time.Date",
"optional": false,
"type": "int32",
"version": 1
},
{
"field": "purchaser",
"optional": false,
"type": "int32"
},
{
"field": "quantity",
"optional": false,
"type": "int32"
},
{
"field": "product_id",
"optional": false,
"type": "int32"
}
]
},
{
"field": "after",
"name": "dbserver1.inventory.orders.Value",
"optional": true,
"type": "struct",
"fields": [
{
"field": "order_number",
"optional": false,
"type": "int32"
},
{
"field": "order_date",
"name": "io.debezium.time.Date",
"optional": false,
"type": "int32",
"version": 1
},
{
"field": "purchaser",
"optional": false,
"type": "int32"
},
{
"field": "quantity",
"optional": false,
"type": "int32"
},
{
"field": "product_id",
"optional": false,
"type": "int32"
}
]
},
{
"field": "source",
"name": "io.debezium.connector.mysql.Source",
"optional": false,
"type": "struct",
"fields": [
{
"field": "version",
"optional": false,
"type": "string"
},
{
"field": "connector",
"optional": false,
"type": "string"
},
{
"field": "name",
"optional": false,
"type": "string"
},
{
"field": "ts_ms",
"optional": false,
"type": "int64"
},
{
"default": "false",
"field": "snapshot",
"name": "io.debezium.data.Enum",
"optional": true,
"type": "string",
"version": 1,
"parameters": {
"allowed": "true,last,false"
}
},
{
"field": "db",
"optional": false,
"type": "string"
},
{
"field": "table",
"optional": true,
"type": "string"
},
{
"field": "server_id",
"optional": false,
"type": "int64"
},
{
"field": "gtid",
"optional": true,
"type": "string"
},
{
"field": "file",
"optional": false,
"type": "string"
},
{
"field": "pos",
"optional": false,
"type": "int64"
},
{
"field": "row",
"optional": false,
"type": "int32"
},
{
"field": "thread",
"optional": true,
"type": "int64"
},
{
"field": "query",
"optional": true,
"type": "string"
}
]
},
{
"field": "op",
"optional": false,
"type": "string"
},
{
"field": "ts_ms",
"optional": true,
"type": "int64"
}
]
},
"payload": {
"op": "u",
"before": {
"order_date": 16816,
"quantity": 1,
"purchaser": 1001,
"order_number": 10001,
"product_id": 102
},
"after": **{
"order_date": 16816,
"quantity": 6,
"purchaser": 1001,
"order_number": 10001,
"product_id": 102
},
"source": {
"query": null,
"thread": 4,
"server_id": 223344,
"version": "1.0.3.Final",
"file": "mysql-bin.000007",
"connector": "mysql",
"pos": 354,
"name": "dbserver1",
"gtid": null,
"row": 0,
"ts_ms": 1591620600000,
"snapshot": "false",
"db": "inventory",
"table": "orders"
},
"ts_ms": 1591620602204
}