canal 整合 springboot
canal
alibaba/canal: Canal 是由阿里巴巴开源的分布式数据库同步系统,主要用于实现MySQL数据库的日志解析和实时增量数据订阅与消费,广泛应用于数据库变更消息的捕获、数据迁移、缓存更新等场景。
项目地址:https://gitcode.com/gh_mirrors/ca/canal
免费下载资源
·
mysql 开启bin_log
vi /etc/my.cnf
末尾增加如下配置
log_bin=mysql-bin
binlog-format=ROW #选择row模式
server-id = 1
expire_logs_days=5 #日志过期时间为5天
重启mysql [5.7]
service mysqld restart
# 查看 binlog日志是否开启 ON 代表已开启
show VARIABLES like 'log_bin'
修改canal 配置
vi canal/conf/canal.properties
#唯一标识 新增
canal.id =123
# 本机ip
canal.register.ip =192.168.1.106
# 默认端口号
canal.port = 11111
vi canal/conf/example/instance.properties
# 对应mysql 地址 用户名 密码
canal.instance.master.address=182.92.99.65:3306
canal.instance.dbUsername=root
canal.instance.dbPassword=123456
# 代表监听 GP数据库下 所有表
canal.instance.filter.regex=GP\\..*
启动 canal
./startup.sh
查看启动日志
cat logs/example/example.log
2021-02-12 16:44:31.053 [main] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal.properties]
2021-02-12 16:44:31.058 [main] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [example/instance.properties]
2021-02-12 16:44:31.606 [main] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal.properties]
2021-02-12 16:44:31.608 [main] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [example/instance.properties]
2021-02-12 16:44:32.378 [main] INFO c.a.otter.canal.instance.spring.CanalInstanceWithSpring - start CannalInstance for 1-example
2021-02-12 16:44:32.404 [main] WARN c.a.o.canal.parse.inbound.mysql.dbsync.LogEventConvert - --> init table filter : ^GP\..*$
2021-02-12 16:44:32.404 [main] WARN c.a.o.canal.parse.inbound.mysql.dbsync.LogEventConvert - --> init table black filter : ^mysql\.slave_.*$
2021-02-12 16:44:32.425 [main] INFO c.a.otter.canal.instance.core.AbstractCanalInstance - start successful....
2021-02-12 16:44:32.864 [destination = example , address = /182.92.97.65:3306 , EventParser] WARN c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - ---> begin to find start position, it will be long time for reset or first position
2021-02-12 16:44:32.865 [destination = example , address = /182.92.97.65:3306 , EventParser] WARN c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - prepare to find start position just show master status
2021-02-12 16:44:34.256 [destination = example , address = /182.92.97.65:3306 , EventParser] WARN c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - ---> find start position successfully, EntryPosition[included=false,journalName=mysql-bin.000001,position=4,serverId=1,gtid=<null>,timestamp=1613118986000] cost : 1382ms , the next step is binlog dump
springboot 引入依赖
<!--springboot-canal快速构建依赖包-->
<dependency>
<groupId>top.javatool</groupId>
<artifactId>canal-spring-boot-starter</artifactId>
<version>1.2.1-RELEASE</version>
</dependency>
canal.server=127.0.0.1:11111
# 对应 canal 主题
canal.destination=example
@CanalTable(value = "sku")
@Component
public class CanalHandler implements EntryHandler<Sku> {
@Override
public void update(Sku before, Sku after) {
System.out.println("监听 跟新操作");
System.out.println(before);
}
}
GitHub 加速计划 / ca / canal
28.21 K
7.57 K
下载
alibaba/canal: Canal 是由阿里巴巴开源的分布式数据库同步系统,主要用于实现MySQL数据库的日志解析和实时增量数据订阅与消费,广泛应用于数据库变更消息的捕获、数据迁移、缓存更新等场景。
最近提交(Master分支:2 个月前 )
1e5b8a20 - 1 个月前
ff82fd65
1 个月前
更多推荐
已为社区贡献2条内容
所有评论(0)