springboot整合canal(完整版)引⼊以下代码不会⼊侵原项⽬结构
⼀、gradle(maven⾃⼰去仓库取)
implementation group: '', name: 'canal.client', version: '1.1.4'
implementation group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.6.3'⼆、⽬录结构
三、代码
CanlEventListener
import annotation.AliasFor; import org.springframework.stereotype.Component;
import java.lang.annotation.*;
/**
* inject the present class to the spring context
* as a listener of the canal event
*
* @author jigua
* @date 2018/3/19
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface CanalEventListener {
@AliasFor(annotation = Component.class)
String value()default"";
}
DeleteListenPoint
import canal.protocol.CanalEntry; import annotation.AliasFor;
import java.lang.annotation.*;
/**
* ListenPoint for delete
*
* @author jigua
* @date 2018/3/19
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ListenPoint(eventType = CanalEntry.EventType.DELETE) public @interface DeleteListenPoint {
/**
* canal destination
* default for all
* @return canal destination
*/
@AliasFor(annotation = ListenPoint.class)
String destination()default"";
/**
* database schema which you are concentrate on
* default for all
* @return canal destination
*/
@AliasFor(annotation = ListenPoint.class)
String[]schema()default{};
/**
* tables which you are concentrate on
* default for all
* @return canal destination
*/
@AliasFor(annotation = ListenPoint.class)
String[]table()default{};
}
EnableCanalClient
import com.fig.CanalClientConfiguration; import com.fig.CanalConfig;
import com.fig.CanalClientConfiguration; import com.fig.CanalConfig;
import t.annotation.Import; import java.lang.annotation.*;
/**
* Enables the canal client
*
* @author jigua
* @date 2018/3/19
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({CanalConfig.class, CanalClientConfiguration.class}) public @interface EnableCanalClient {
}
springboot结构InsertListenPoint
import canal.protocol.CanalEntry; import annotation.AliasFor;
import java.lang.annotation.*;
/**
* ListenPoint for insert
*
* @author jigua
* @date 2018/3/19
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ListenPoint(eventType = CanalEntry.EventType.INSERT) public @interface InsertListenPoint {
/**
* canal destination
* default for all
* @return canal destination
*/
@AliasFor(annotation = ListenPoint.class)
String destination()default"";
/**
* database schema which you are concentrate on
* default for all
* @return canal destination
*/
@AliasFor(annotation = ListenPoint.class)
String[]schema()default{};
/**
* tables which you are concentrate on
* default for all
* @return canal destination
*/
@AliasFor(annotation = ListenPoint.class)
String[]table()default{};
}
ListenPoint
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论