You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debezium中如何将不同数据库表路由至不同Topic?

Debezium多表Topic路由配置方案

针对你的需求——默认表路由到user_service.$tableName,指定表路由到专属服务Topic,可通过配置多个ByLogicalTableRouter实例实现多表路由,完整配置如下:

"transforms": "unwrap,RerouteNotifications,RerouteAlerts,RerouteDefault",

// 处理notifications表路由
"transforms.RerouteNotifications.type": "io.debezium.transforms.ByLogicalTableRouter",
"transforms.RerouteNotifications.topic.regex": ".*\\.notifications",
"transforms.RerouteNotifications.topic.replacement": "notification_service.notifications",

// 处理alerts表路由
"transforms.RerouteAlerts.type": "io.debezium.transforms.ByLogicalTableRouter",
"transforms.RerouteAlerts.topic.regex": ".*\\.alerts",
"transforms.RerouteAlerts.topic.replacement": "alert_service.alerts",

// 处理users和clients默认路由
"transforms.RerouteDefault.type": "io.debezium.transforms.ByLogicalTableRouter",
"transforms.RerouteDefault.topic.regex": "(.*)\\.(users|clients)",
"transforms.RerouteDefault.topic.replacement": "user_service.${2}"

配置说明

  1. 路由顺序优先级:先配置特殊表(notifications、alerts)的路由规则,再处理默认表(users、clients),避免匹配逻辑冲突。
  2. 正则匹配逻辑:.*\\.表名适配Debezium默认生成的Topic格式(通常为数据库名.模式名.表名),确保精准定位对应表的事件流。
  3. 动态Topic生成:默认表的路由使用${2}引用正则捕获到的表名,自动生成user_service.表名格式的目标Topic。
  4. 拼写修正:你原有配置中的notificaton_service为拼写错误,已修正为notification_service。

内容的提问来源于stack exchange,提问作者JDev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 07:25:34