update 2021年11月1日16:33:36
parent
9c45547879
commit
5a83d206ba
|
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mystyle-cloud-parent</artifactId>
|
||||
<groupId>com.zhangmeng</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mystyle-cloud-canal</artifactId>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.xpand</groupId>
|
||||
<artifactId>starter-canal</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-sleuth</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.zhangmeng.canal;
|
||||
|
||||
|
||||
import com.xpand.starter.canal.annotation.EnableCanalClient;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
|
||||
@EnableDiscoveryClient
|
||||
@EnableCanalClient
|
||||
public class CanalApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CanalApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package com.zhangmeng.canal.listener;
|
||||
|
||||
import com.alibaba.otter.canal.protocol.CanalEntry;
|
||||
import com.xpand.starter.canal.annotation.*;
|
||||
|
||||
/**
|
||||
* @author 转身的背影在心底里沉沦
|
||||
* @version 1.0
|
||||
* @date 2021/9/13 0:05
|
||||
*/
|
||||
@CanalEventListener
|
||||
public class CanalDataEventListener {
|
||||
|
||||
/***
|
||||
* 增加数据监听
|
||||
* @param eventType
|
||||
* @param rowData
|
||||
*/
|
||||
@InsertListenPoint
|
||||
public void onEventInsert(CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
|
||||
rowData.getAfterColumnsList().forEach((c) -> System.out.println("By--Annotation: " + c.getName() + " :: " + c.getValue()));
|
||||
}
|
||||
|
||||
/***
|
||||
* 修改数据监听
|
||||
* @param rowData
|
||||
*/
|
||||
@UpdateListenPoint
|
||||
public void onEventUpdate(CanalEntry.RowData rowData) {
|
||||
System.out.println("UpdateListenPoint");
|
||||
rowData.getAfterColumnsList().forEach((c) -> System.out.println("By--Annotation: " + c.getName() + " :: " + c.getValue()));
|
||||
}
|
||||
|
||||
/***
|
||||
* 删除数据监听
|
||||
* @param eventType
|
||||
*/
|
||||
@DeleteListenPoint
|
||||
public void onEventDelete(CanalEntry.EventType eventType) {
|
||||
System.out.println("DeleteListenPoint");
|
||||
}
|
||||
|
||||
/***
|
||||
* 自定义数据修改监听
|
||||
* @param eventType
|
||||
* @param rowData
|
||||
*/
|
||||
@ListenPoint(destination = "example", schema = "mystyle-blog", table = {"user", "role"}, eventType = CanalEntry.EventType.QUERY)
|
||||
public void onEventCustomUpdate(CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
|
||||
System.err.println("QUERY");
|
||||
rowData.getAfterColumnsList().forEach((c) -> System.out.println("By--Annotation: " + c.getName() + " :: " + c.getValue()));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
server:
|
||||
port: 31004
|
||||
spring:
|
||||
application:
|
||||
name: mystyle-cloud-canan
|
||||
zipkin:
|
||||
sender:
|
||||
type: web
|
||||
base-url: http://localhost:9411/
|
||||
service:
|
||||
name: mystyle-cloud-file
|
||||
sleuth:
|
||||
sampler:
|
||||
probability: 1
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
canal:
|
||||
client:
|
||||
instances:
|
||||
example:
|
||||
host: 127.0.0.1
|
||||
port: 11111
|
||||
Loading…
Reference in New Issue