文章目录
背景
1、内容
通过监听mysql的主库的写、删、更新操作产生的binlog日志,来做业务(eg:监控数据、同步数据等)
2、作用
- 无感知
服务A编辑数据库,服务B监听A的mysql内容,对于A而言,感知不到服务B的存在
3、缺点
- 主库压力大
如果写的并发很高,服务B监听binlog,同步信息,会对主库造成压力
- 必须写库成功后,才能监听到binlog同步的内容
假如B站用户点赞行为,A服务需要写库,写完库后,B服务需要同步财务结算up主收益
假如A写库失败了,B服务监听不到binlog,本次点赞行为就丢失了。这种场景不适合
这种场景可以使用MQ来解决
快速入门
1、pom
<!-- https://mvnrepository.com/artifact/com.gitee.Jmysy/binlog4j-spring-boot-starter -->
<dependency>
<groupId>com.gitee.Jmysy</groupId>
<artifactId>binlog4j-spring-boot-starter</artifactId>
<version>1.9.1</version>
</dependency>
- 支持集群模式
- 宕机续读(服务A写mysql,服务B监听,假如在服务B宕机期间,A写了新数据,则B重新启动后,仍可以获取到期间的binlog同步内容),实现:通过redis配置的serverId,去对应的binlogfileName + position获取
- 数据转换
2、yml配置
spring:
binlog4j:
redis-config:
host: 127.0.0.1
port: 6379
database: 1
client-configs:
master:
host: "127.0.0.1"
port: 3306
username: "root"
password: "941123"
mode

最低0.47元/天 解锁文章
6683

被折叠的 条评论
为什么被折叠?



