| | |
| | | zookeeper-address: # zookeeper 地址(开启集群的情况下生效), 例: 192.168.0.1:2181,192.168.0.2:2181,192.168.0.3:2181
|
| | | acquire-interval: 1000 # 未拉取到消息情况下,获取消息的时间间隔毫秒值
|
| | | subscribe: .*\\..* # 默认情况下拉取所有库、所有表
|
| | | prod:
|
| | | example: example1
|
| | | database: books
|
| | |
|
| | | ```
|
| | |
|
| | |
| | | public class CanalListenerTest {
|
| | |
|
| | | /**
|
| | | * 目前 Listener 方法的参数必须为 CanalEntry.EventType eventType, CanalEntry.RowData rowData
|
| | | * 目前 Listener 方法的参数必须为 CanalEntry.EventType , CanalEntry.RowData |
| | | * 程序在启动过程中会做检查
|
| | | */
|
| | | |
| | | /**
|
| | | * 监控更新操作
|
| | | * 支持动态参数配置,配置项需在 yml 或 properties 进行配置
|
| | | * 目标是 ${prod.example} 的 ${prod.database} 库 users表
|
| | | */
|
| | | @CanalUpdateListener(destination = "${prod.example}", database = "${prod.database}", table = {"users"})
|
| | | public void listenerExampleBooksUsers(CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
|
| | | printChange("listenerExampleBooksUsers",eventType, rowData);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 监控更新操作 ,目标是 example的 books库 users表
|
| | |
| | |
|
| | | public void printChange(String method,CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
|
| | | if (eventType == CanalEntry.EventType.DELETE) {
|
| | | rowData.getAfterColumnsList().stream().collect(Collectors.toList()).forEach(ele -> {
|
| | | rowData.getBeforeColumnsList().stream().collect(Collectors.toList()).forEach(ele -> {
|
| | | System.out.println("[方法: "+method+" , delete 语句 ] --->> 字段名: " + ele.getName() + ", 删除的值为: " + ele.getValue());
|
| | | });
|
| | | }
|