通过java方式监听mysql的binlog变化
1引入依赖
<dependency>
<groupId>com.xy</groupId>
<artifactId>xy-core-data-mysql-binlog-boot</artifactId>
<version>${xy-core-data-mysql-binlog-boot.version}</version>
</dependency>
2.添加配置
spring.mysql.binlog.enable=true
spring.mysql.binlog.host=127.0.0.1
spring.mysql.binlog.port=3306
spring.mysql.binlog.schema=company-demo
spring.mysql.binlog.username=root
spring.mysql.binlog.password=1q2w3e4r@
spring.mysql.binlog.server-id=2
3.实现接口
package com.company.demo.message.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* <p>description</p >
*
* @author jack.li
* @version 1.0
* @date 2022/3/22 下午12:25
*/
@Slf4j
@Component
public class MysqlBinLogChangeImplListener implements MysqlBinLogChangeListener {
@Override
public void insert(String tableName, WriteRowsEventData writeRowsEventData) {
log.info("insert.........................");
}
@Override
public void delete(String tableName, DeleteRowsEventData deleteRowsEventData) {
log.info("delete...........................");
}
@Override
public void update(String tableName, UpdateRowsEventData updateRowsEventData) {
log.info("update...........................");
}
}