开发者社区> 问答> 正文

canal-adapter 可不可以连接两个destination

环境信息

canal version mysql version

问题描述

由于业务需要,server端要订阅两个mysql实例,但是canal-adapter-sync-es里一个yml就是需要跨库查询。但是一个yml里面只能填一个destination,能填两个吗

原提问者GitHub用户bestzhao

展开
收起
古拉古拉 2023-05-08 14:59:10 133 0
3 条回答
写回答
取消 提交回答
  • 暂时还不行,不过后续会增加子索引配置功能

    原回答者GitHub用户rewerma

    2023-05-09 18:04:37
    赞同 展开评论 打赏
  • 可以使用 YAML 的 merge 方法将两个 destination 配置合并为一个,然后将合并后的配置写入 canal-adapter-sync-es 中。

    以下是一个示例 YAML 文件:

    yaml

    config1.yml

    • name: server1
      replicas: 2
      host: server1_host
      username: server1_username
      password: server1_password
      database: server1_database
      destination:
      • name: table1
        host: table1_host
        username: table1_username
        password: table1_password
        database: table1_database
      • name: table2
        host: table2_host
        username: table2_username
        password: table2_password
        database: table2_database

    config2.yml

    • name: server2
      replicas: 2
      host: server2_host
      username: server2_username
      password: server2_password
      database: server2_database
      destination:
      • name: table1
        host: table1_host
        username: table1_username
        password: table1_password
        database: table1_database
      • name: table2
        host: table2_host
        username: table2_username
        password: table2_password
        database: table2_database 然后,可以使用以下命令将两个 destination 配置合并为一个:

    bash cat config1.yml | while read line; do
    destination=$(echo $line | awk -F '-' '{print $1}')
    cat $line >> $destination
    done | awk '{print "\n"}1' | sort -u > merged_config 然后,可以将合并后的配置写入 canal-adapter-sync-es 中:

    bash

    2023-05-08 15:23:59
    赞同 展开评论 打赏
  • 随心分享,欢迎友善交流讨论:)

    不建议在一个yml文件里面同时配置两个destination,因为它们的配置可能会有所不同,例如MySQL的账号密码、binlog位置等等。而且,如果两个destination的数据源不同,可能需要连接不同的Elasticsearch集群,这也需要在yml文件里面进行配置。因此,建议分别为两个destination配置不同的yml文件。如果需要跨库查询,可以在canal-adapter-sync-es代码中实现跨库查询逻辑,例如使用多个JdbcTemplate连接不同的MySQL实例,然后将查询结果合并到同一个Elasticsearch索引中。

    2023-05-08 15:17:15
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载