将数据从mysql传递到kafka produce的最佳方式是什么
我知道有很好的kafka连接器。然而,我想使用springboot框架。因为我需要转换数据并与其他http结果合并,然后我想产生数据到kafka。
那么有没有什么好的例子,github,博客wahtever~?
发布于 2020-07-22 00:48:14
最简单的方法是使用Camel和camel-debezium组件。文档中的一个例子是following。在推送到Kafka主题之前,您可以使用所有Camel功能进行任何类型的转换或丰富。我认为如果mysql中的源数据不代表你的真实来源,并且你需要在推送到Kafka之前进行过滤/转换,那么这可能是一个合法的选择。
监听事件:
from("debezium-mysql:dbz-test-1?offsetStorageFileName=/usr/offset-file-1.dat&databaseHostName=localhost&databaseUser=debezium&databasePassword=dbz&databaseServerName=my-app-connector&databaseHistoryFileName=/usr/history-file-1.dat")
.log("Event received from Debezium : ${body}")
.log(" with this identifier ${headers.CamelDebeziumIdentifier}")
.log(" with these source metadata ${headers.CamelDebeziumSourceMetadata}")
.log(" the event occured upon this operation '${headers.CamelDebeziumSourceOperation}'")
.log(" on this database '${headers.CamelDebeziumSourceMetadata[db]}' and this table '${headers.CamelDebeziumSourceMetadata[table]}'")
.log(" with the key ${headers.CamelDebeziumKey}")
.log(" the previous value is ${headers.CamelDebeziumBefore}")阅读/转换后将Produce转换为Kafka:
.to("kafka:{{topic}}")另外,请查看Spring boot guide
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-debezium-mysql-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>一个包含驼峰转换的详细github示例是here。
https://stackoverflow.com/questions/63017251
复制相似问题