canal继续

整合springboot更方便的使用功能。先下载该项目。canal服务可以看我上篇文章
https://github.com/stormbirds/spring-boot-starter-canal
将该项目生成jar包

1.下载完成进入项目根目录starter-canal 中 命令行如下: mvn install
2.等待打包完成 target目录下生成 starter-canal-0.0.1-SNAPSHOT.jar
3.在当前目录下输入命令: mvn install:install-file "-DgroupId=com.xpand" "-DartifactId=starter-canal" "-Dversion=0.0.1-SNAPSHOT" "-Dpackaging=jar" "-Dfile=starter-canal-0.0.1-SNAPSHOT.jar"

根据提示找到生成的jar包,如图
在这里插入图片描述
项目使用该jar包,放入到这,然后build path,依赖如下引入
在这里插入图片描述

<dependency>
	        <groupId>com.xpand</groupId>
			<artifactId>starter-canal</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/src/main/resources/lib/starter-canal-0.0.1-SNAPSHOT.jar</systemPath>
        </dependency>
		<dependency>
		    <groupId>com.alibaba.otter</groupId>
		    <artifactId>canal.client</artifactId>
		    <version>1.1.4</version>
		</dependency>

按照官方的demo直接使用
配置文件加上该配置信息

canal.client.instances.example.host=127.0.0.1
canal.client.instances.example.port=11111

启动类上加上使用注解@EnableCanalClient
在这里插入图片描述

import com.alibaba.otter.canal.protocol.CanalEntry;
import com.xpand.starter.canal.annotation.CanalEventListener;
import com.xpand.starter.canal.annotation.DeleteListenPoint;
import com.xpand.starter.canal.annotation.InsertListenPoint;
import com.xpand.starter.canal.annotation.ListenPoint;
import com.xpand.starter.canal.annotation.UpdateListenPoint;

@CanalEventListener
public class MyEventListener {

//检测所有插入
    @InsertListenPoint
    public void onEvent(CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
        //do something...
    }

//检测所有修改
    @UpdateListenPoint
    public void onEvent1(CanalEntry.RowData rowData) {
        //do something...
    	System.err.println(rowData.getAfterColumnsList());
    }

//检测所有删除
    @DeleteListenPoint
    public void onEvent3(CanalEntry.EventType eventType) {
        //do something...
    }

//通过参数进行监控
    @ListenPoint(destination = "example", schema = "canal-test", table = {"t_user", "test_table"}, eventType = CanalEntry.EventType.UPDATE)
    public void onEvent4(CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
        //do something...
    }
}

测试,随便修改一下数据
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值