canal adapter

1、下載 canal adapter

wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.adapter-1.1.4.tar.gz
https://github.com/alibaba/canal/wiki/ClientAdapter

2、安裝canal adapter

mkdir /yourpath/soft/canal.adapter-1.1.4
tar zxvf canal.adapter-1.1.4.tar.gz  -C /yourpath/soft/canal.adapter-1.1.4

編輯application.yml

server:
  port: 8081
spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
    default-property-inclusion: non_null

canal.conf:
  mode: tcp # kafka rocketMQ
#  canalServerHost: 127.0.0.1:11111
 #HA ZK
  zookeeperHosts: 192.168.1.111:2181
 #擴(kuò)展監(jiān)控手機(jī)
  mobiles: 
#擴(kuò)展訂閱
  subscribe: seata_order.t_order,seata_order.Test
#  mqServers: 127.0.0.1:9092 #or rocketmq
#  flatMessage: true
  batchSize: 500
  syncBatchSize: 1000
#錯誤重試次數(shù)
  retries: 3
  timeout:
  accessKey:
  secretKey:
  srcDataSources:
    defaultDS:
#源數(shù)據(jù)地址
      url: jdbc:mysql://192.168.1.115:3306/seata_order?useUnicode=true
      username: root
      password: 123456
  canalAdapters:  #可配置多個實例
  - instance: example # canal instance Name or mq topic name
    groups:
    - groupId: g1
      outerAdapters:
      - name: logger
      - name: rdb #可配置多個目標(biāo)數(shù)據(jù)庫
# 在所有目標(biāo)端的同步中key是一個必須要配置的參數(shù),不配置可能會出現(xiàn)數(shù)據(jù)丟失的問題
        key: mysql1
        properties:
          jdbc.driverClassName: com.mysql.jdbc.Driver
#目標(biāo)數(shù)據(jù)庫地址
          jdbc.url: jdbc:mysql://192.168.1.115:3306/seata_account?useUnicode=true
          jdbc.username: root
          jdbc.password: 123456
#      - name: rdb
#        key: oracle1
#        properties:
#          jdbc.driverClassName: oracle.jdbc.OracleDriver
#          jdbc.url: jdbc:oracle:thin:@localhost:49161:XE
#          jdbc.username: mytest
#          jdbc.password: m121212
#      - name: rdb
#        key: postgres1
#        properties:
#          jdbc.driverClassName: org.postgresql.Driver
#          jdbc.url: jdbc:postgresql://localhost:5432/postgres
#          jdbc.username: postgres
#          jdbc.password: 121212
#          threads: 1
#          commitSize: 3000
#     hbase
#      - name: hbase
#        properties:
#          hbase.zookeeper.quorum: 127.0.0.1
#          hbase.zookeeper.property.clientPort: 2181
#          zookeeper.znode.parent: /hbase
#     es
#      - name: es
#        hosts: 127.0.0.1:9300 # 127.0.0.1:9200 for rest mode
#        properties:
#          mode: transport # or rest
#          # security.auth: test:123456 #  only used for rest mode
#          cluster.name: elasticsearch

配置rdb目錄下面表的映射文件

dataSourceKey: defaultDS
destination: example
groupId: g1
# 在所有目標(biāo)端的同步中outerAdapterKey是一個必須要配置的參數(shù),不配置可能會出現(xiàn)數(shù)據(jù)丟失的問題
# 對應(yīng)application.yml中key字段
outerAdapterKey: mysql1
concurrent: true
dbMapping:
  #master數(shù)據(jù)庫
  database: mytest
  table: user
#目標(biāo)數(shù)據(jù)庫表
  targetTable: mytest2.user
  targetPk: #主鍵映射
    id: id   #復(fù)合主鍵可以映射多個
#  mapAll: true  #字段完全一樣可以打開
  targetColumns:  #字段映射
    id:
    name:
    role_id:
    c_time:
    test1:
  etlCondition: "where c_time>={}"
  commitBatch: 3000 # 批量提交的大小


## Mirror schema synchronize config
#dataSourceKey: defaultDS
#destination: example
#groupId: g1
#outerAdapterKey: mysql1
#concurrent: true
#dbMapping:
#  mirrorDb: true
#  database: mytest

啟動canal.adapter : ./startup.sh

Canal-Adapter源碼在IDEA部署運行

下載地址:https://github.com/alibaba/canal

源碼導(dǎo)入到IDEA中的結(jié)構(gòu)如下


image.png

修改源碼后編譯打包


image.png

canal-adapter從數(shù)據(jù)庫讀取配置代碼解析及改造

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容