网站首页 > 博客文章 正文
在上一期我们对datax进行了技术调研DataX数据异构、数据同步神器,这一次我们集成一个RocketMQ写插件,能够非常方便对将mysql数据同步到MQ中,下面来总结下具体步骤。
1.下载datax源码,下载地址:
https://github.com/alibaba/DataX
2.按照已有插件的代码结构建立rocketmqwriter的代码目录如下:
package.xml:定义了插件具体的打包路径
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id></id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>plugin.json</include>
</includes>
<outputDirectory>plugin/writer/ons-rocketmqwriter</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>ons-rocketmqwriter-0.0.1-SNAPSHOT.jar</include>
</includes>
<outputDirectory>plugin/writer/ons-rocketmqwriter</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>plugin/writer/ons-rocketmqwriter/libs</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
- Key类:获取配置文件json传递的参数;
- MQColumn类:获取属性column[]的值;
- MQFieldType类:获取属性column[]值的类型;
- MQWriterErrorCode类:定义MQ解析过程中的异常错误码;
- ONS_RocketMQWriter类:核心实现,数据解析以及MQ消息统一推送。
plugin.json:配置插件统一扫描文件实现类,即扫描ONS_RocketMQWriter类,配置如下:
{
"name": "ons-rocketmqwriter",
"class": "com.alibaba.datax.plugin.writer.ons_rocketmqwriter.ONS_RocketMQWriter",
"description": "适用于: 阿里云版RocketMQ",
"developer": "wenqi"
}
完成以上步骤,还需要修改Datax主工程配置文件package.xml,添加rocketmqwriter模块,代码如下:
<fileSet>
<directory>ons-rocketmqwriter/target/datax/</directory>
<includes>
<include>**/*.*</include>
</includes>
<outputDirectory>datax</outputDirectory>
</fileSet>
3.插件代码完成后,本地调试的话,需要修改core包下的Engine类,1)设置运行的datax的home目录;2)设置datax的运行脚本信息。截图如下:
4.本地调试完成后进行maven打包,在idea的terminal中执行 mvn -U clean package assembly:assembly -Dmaven.test.skip=true
5.编写json文件,mysql-mq.json
{
"job": {
"setting": {
"speed": {
"channel": 1,
"record": -1,
"byte": -1
}
},
"content": [{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "root",
"password": "******",
"connection": [
{
"querySql": [
"select id from table where id<7506000;"
],
"jdbcUrl": [
"jdbc:mysql://pc-xxx.rwlb.rds.aliyuncs.com:3306/db"
]
}
]
}
},
"writer": {
"name": "ons-rocketmqwriter",
"parameter": {
"nameServer": "http://xxx.mq-internet.aliyuncs.com:80",
"accessKey": "xxxxxx",
"secretKey": "xxxxxx",
"topic": "topic_name",
"tags": "*",
"batchSize":1000,
"column": [
{"name": "tableId", "type": "string"}
]
}
}
}]
}
}
6.执行脚本命令便可以完成mysql数据按照规则同步给RocketMQ了
bin/datax.py job/mysql-mq.json
不断分享开发过程用到的技术和面试经常被问到的问题,如果您也对IT技术比较感兴趣可以「关注」我
猜你喜欢
- 2025-05-02 spring Boot必用依赖框架(spring boot 依赖)
- 2025-05-02 Navigating global shifts and forging a path for emerging economies
- 2025-05-02 《Servlet》第05节:创建第一个Servlet程序(HelloSevlet)
- 2025-05-02 Terminal affliction - China’s vanishing coach stations
- 2025-05-02 连载嵌入式Linux开发教程:初始Ubuntu
- 2025-05-02 Win10预览版9879硬盘丢失的Linux解决方案
- 2025-05-02 idea插件之Grep Console(工欲善其事,必先利其器)
- 2025-05-02 mybatis-plus保姆级入门教程,手把手教你轻松实现增删改查
- 2025-05-02 java日常开发笔记和开发问题记录(java开发问题总结)
- 2025-05-02 IDEA界面太丑??尝试一下这几个插件
你 发表评论:
欢迎- 07-08Google Cloud Platform 加入支持 Docker 的容器引擎
- 07-08日本KDDI与Google Cloud 签署合作备忘录,共探AI未来
- 07-08美国Infoblox与Google Cloud合作推出云原生网络和安全解决方案
- 07-08GoogleCloud为Spanner数据库引入HDD层,将冷存储成本降低80%
- 07-08谷歌推出Cloud Dataproc,缩短集群启动时间
- 07-08Infovista与Google Cloud携手推进射频网络规划革新
- 07-08比利时Odoo与Google Cloud建立增强合作,扩大全球影响力
- 07-08BT 和 Google Cloud 通过 Global Fabric 加速 AI 网络
- 最近发表
-
- Google Cloud Platform 加入支持 Docker 的容器引擎
- 日本KDDI与Google Cloud 签署合作备忘录,共探AI未来
- 美国Infoblox与Google Cloud合作推出云原生网络和安全解决方案
- GoogleCloud为Spanner数据库引入HDD层,将冷存储成本降低80%
- 谷歌推出Cloud Dataproc,缩短集群启动时间
- Infovista与Google Cloud携手推进射频网络规划革新
- 比利时Odoo与Google Cloud建立增强合作,扩大全球影响力
- BT 和 Google Cloud 通过 Global Fabric 加速 AI 网络
- NCSA和Google Cloud合作开发AI驱动的网络防御系统,加强泰国网络空间的安全性
- SAP将在沙特阿拉伯 Google Cloud 上推出BTP服务
- 标签列表
-
- ifneq (61)
- 字符串长度在线 (61)
- googlecloud (64)
- messagesource (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)