canal 整合RabbitMQ

环境如下:

canal: 1.15-alpha-1

mysql  5.6.49

rabbitmq 3.7.14

Erlang 21.3

 

canal 安装和启动 见上篇文章 canal快速安装启动

 

但是这个拿到的数据,不知道怎么处理 看看如果丢到mq,我从mq取到的数据格式 

{
    "data":[
        {
            "id":"23",
            "name":"sdfs",
            "age":"10",
            "sex":"1",
            "created_at":"2010-09-09 11:11:11",
            "updated_at":"2020-08-14 23:57:34"
        }
    ],
    "database":"test",
    "es":1597420654000,
    "id":1,
    "isDdl":false,
    "mysqlType":{
        "id":"int(11)",
        "name":"varchar(255)",
        "age":"int(11)",
        "sex":"int(255)",
        "created_at":"timestamp",
        "updated_at":"timestamp"
    },
    "old":[
        {
            "name":"er",
            "updated_at":"2020-07-25 09:27:35"
        }
    ],
    "pkNames":[
        "id"
    ],
    "sql":"",
    "sqlType":{
        "id":4,
        "name":12,
        "age":4,
        "sex":4,
        "created_at":93,
        "updated_at":93
    },
    "table":"user",
    "ts":1597422036430,
    "type":"UPDATE"
}

 

这个就很好用了,直接拿data字段进行更新就行了

type 会有  UPDATE  DELETE INSERT 

canal 官方文档 说是队列只支持 kafka 和 rocketmq 

但是现在的版本已经支持 rabbitmq了  

  

vim conf/canal.properties

canal.mq.servers = 192.168.33.60
canal.mq.vhost=/
canal.mq.exchange=exchange_user_sync
canal.mq.username=admin
canal.mq.password=admin


canal.serverMode = rabbitmq

 

vim conf/example/instance.properties

canal.instance.master.address=192.168.33.60:3306  改为我的数据库ip


# username/password  默认就是这样的,按照官方的例子授权 都可以不用改了,如果自己授权其他用户改动
canal.instance.dbUsername=canal
canal.instance.dbPassword=canal
canal.instance.connectionCharset = UTF-8
# enable druid Decrypt database password
canal.instance.enableDruid=false


canal.mq.topic=example    mq路由  到时候 交换机和队列绑定要设置route为 example

 

 

canal 整合RabbitMQ_第1张图片

 

你可能感兴趣的:(canal 整合RabbitMQ)