概述
- mysql上创建database、创建table、插入数据
use test;
CREATE TABLE `canal_test` (
`id` bigint(20) unsigned zerofill NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL COMMENT '姓名',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=utf8mb4
- canal中进行相关的instance配置
vi conf/example/instance.properties
# enable gtid use true/false
canal.instance.gtidon=false
# position info
canal.instance.master.address={mysql.ip}:3306
canal.instance.master.journal.name=mysql-bin.000004
#mysql上执行show master status
canal.instance.master.position=13872
vi conf/canal.properties
# tcp, kafka, RocketMQ
canal.serverMode = kafka
canal.mq.servers = {kafka.ip}:{kafka.port}
修改后重启sh bin/restart.sh
3. 确保kafka启动好
打开kafka并且控制台启动consumer查看mq消息
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic example --from-beginning
- 在mysql的canal_test表中插入数据
insert into test.canal_test(name) values ("name4");
- 查看mq消息
{"data":[{"id":"171","name":"name4"}],"database":"test","es":1585304182000,"id":4,"isDdl":false,"mysqlType":{"id":"bigint(20) unsigned zerofill","name":"varchar(50)"},"old":null,"pkNames":["id"],"sql":"","sqlType":{"id":-5,"name":12},"table":"canal_test","ts":1585304182248,"type":"INSERT"}
进行format
{
"data": [
{
"id": "171",
"name": "name4"
}
],
"database": "test",
"es": 1585304182000,
"id": 4,
"isDdl": false,
"mysqlType": {
"id": "bigint(20) unsigned zerofill",
"name": "varchar(50)"
},
"old": null,
"pkNames": [
"id"
],
"sql": "",
"sqlType": {
"id": -5,
"name": 12
},
"table": "canal_test",
"ts": 1585304182248,
"type": "INSERT"
}
最后
以上就是仁爱乐曲为你收集整理的原生canal简单使用测试的全部内容,希望文章能够帮你解决原生canal简单使用测试所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复