canal 配置 多個監聽 推送到不同mq


canal整合rabbitmq  見上篇  

 

如果想監聽不同庫 不同表到不同隊列如何操作 

1. vim canal.properties

canal.destinations = route1,route2

設置目的地為多個  對應的目錄是conf下的對應名字的目錄 

 

2 復制example 為新的 

cp -r example route1
cp -r example route2

 

chmod -R 777 route1

chmod -R 777 route2

 

rm -rf example/

 

3 cd route1  設置監聽表為test庫的uesr表 

vim instance.properties

canal.instance.filter.regex=test.user  

canal.mq.topic=route1

 

4 cd route2 

vim instance.properties

canal.instance.filter.regex=test.tests

canal.mq.topic=route2

 

表過濾規則 規定要監聽那些庫 那些表

canal.instance.filter.regex 

mysql 數據解析關注的表,Perl正則表達式.多個正則之間以逗號(,)分隔,轉義符需要雙斜杠(\\) 
常見例子:
1. 所有表:.* or .*\\..*
2. canal schema下所有表: canal\\..*
3. canal下的以canal打頭的表:canal\\.canal.*
4. canal schema下的一張表:canal.test1
5. 多個規則組合使用:canal\\..*,mysql.test1,mysql.test2 (逗號分隔)
注意:此過濾條件只針對row模式的數據有效(ps. mixed/statement因為不解析sql,所以無法准確提取tableName進行過濾)

 

 

5 手動建立隊列 綁定 到交換機,用定義的route1 和route2 

 

 

 

分別更改兩個表數據 

 

 

 

結果兩個隊列都分別收到數據

 

 

 

 

 

{"data":[{"id":"1","name":"3234234","age":"10","sex":"1","created_at":"2010-09-09 11:11:11","updated_at":"2020-08-15 00:56:53"}],"database":"test","es":1597424213000,"id":2,"isDdl":false,"mysqlType":{"id":"int(11)","name":"varchar(255)","age":"int(11)","sex":"int(255)","created_at":"timestamp","updated_at":"timestamp"},"old":[{"name":"sdsf","updated_at":"2020-08-15 00:39:33"}],"pkNames":["id"],"sql":"","sqlType":{"id":4,"name":12,"age":4,"sex":4,"created_at":93,"updated_at":93},"table":"user","ts":1597424213307,"type":"UPDATE"}
 
 
{"data":[{"id":"2","name":"sdsdf","age":"10","sex":"1","created_at":"2010-09-09 11:11:11","updated_at":"2020-08-15 00:57:29"}],"database":"test","es":1597424249000,"id":3,"isDdl":false,"mysqlType":{"id":"int(11)","name":"varchar(255)","age":"int(11)","sex":"int(255)","created_at":"timestamp","updated_at":"timestamp"},"old":[{"name":"wersdf","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":"tests","ts":1597424249772,"type":"UPDATE"}
  

 

參考 https://blog.csdn.net/hyx1990/article/details/52524115


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM