我正在构建一个数据同步器,它从MySQL Source捕获数据更改,并将数据导出到hive。
我选择使用Kafka Connect来实现这一点。我使用Debezium作为源连接器,使用合流hdfs作为汇点连接器。
Debezium提供了一个单一的消息转换,让我可以从复杂的事件消息中提取after
字段。我做了与列出的文档相同的配置,但它不起作用。
{
// omit ...
"transform": "unwrap",
"transform.unwrap.type": "io.debezium.transforms.ExtractNewRecordState"
}
我已经尝试在源连接器端和接收连接器端配置转换,但它仍然无法工作。事实上,当我在源连接器端配置它,然后检查相应主题中的消息时,我发现消息仍然包含所有字段,包括before
、source
等。
ythh@openstack2:~/confluent-5.5.0$ bin/kafka-avro-console-consumer --from-beginning --bootstrap-server localhost:9092 --topic dbserver1.test_data_1.student3
{"before":null,"after":{"dbserver1.test_data_1.student3.Value":{"id":1,"name":"ggg"}},"source":{"version":"1.1.1.Final","connector":"mysql","name":"dbserver1","ts_ms":1589005572000,"snapshot":{"string":"false"},"db":"test_data_1","table":{"string":"student3"},"server_id":1,"gtid":null,"file":"mysql-bin.000011","pos":9474,"row":0,"thread":{"long":6013},"query":null},"op":"c","ts_ms":{"long":1589005572172},"transaction":null}
{"before":null,"after":{"dbserver1.test_data_1.student3.Value":{"id":2,"name":"no way"}},"source":{"version":"1.1.1.Final","connector":"mysql","name":"dbserver1","ts_ms":1589005893000,"snapshot":{"string":"false"},"db":"test_data_1","table":{"string":"student3"},"server_id":1,"gtid":null,"file":"mysql-bin.000011","pos":11218,"row":0,"thread":{"long":6030},"query":null},"op":"c","ts_ms":{"long":1589005893773},"transaction":null}
{"before":null,"after":{"dbserver1.test_data_1.student3.Value":{"id":3,"name":"not work"}},"source":{"version":"1.1.1.Final","connector":"mysql","name":"dbserver1","ts_ms":1589005900000,"snapshot":{"string":"false"},"db":"test_data_1","table":{"string":"student3"},"server_id":1,"gtid":null,"file":"mysql-bin.000011","pos":11501,"row":0,"thread":{"long":6030},"query":null},"op":"c","ts_ms":{"long":1589005900724},"transaction":null}
我还检查了kafka连接日志,以下是一些输出:
ythh@openstack2:~/kafka_2.12-2.5.0/logs$ cat connect.log | grep transform
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
[2020-05-09 14:29:30,470] INFO transform.unwrap.type = io.debezium.transforms.ExtractNewRecordState (io.debezium.connector.common.BaseSourceTask:97)
[2020-05-09 14:29:30,470] INFO transform = unwrap (io.debezium.connector.common.BaseSourceTask:97)
[2020-05-09 14:29:30,471] INFO transform.unwrap.drop.tombstones = false (io.debezium.connector.common.BaseSourceTask:97)
[2020-05-09 14:29:30,471] INFO transform.unwrap.delete.handling.mode = rewrite (io.debezium.connector.common.BaseSourceTask:97)
transforms = []
transforms = []
[2020-05-09 14:29:32,419] INFO transform.unwrap.type = io.debezium.transforms.ExtractNewRecordState (io.debezium.connector.common.BaseSourceTask:97)
[2020-05-09 14:29:32,419] INFO transform = unwrap (io.debezium.connector.common.BaseSourceTask:97)
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
transforms = []
看起来您输入了一个错误(transform
而不是transforms
(。尝试此配置:
{
// omit ...
"transforms": "unwrap",
"transforms.unwrap.type": "io.debezium.transforms.ExtractNewRecordState"
}