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

使用ReplicatorSourceConnector+RegexRouter SMT无法重命名主题求助

问题解决:RegexRouter SMT无法重命名ReplicatorSourceConnector主题

问题原因

你的正则表达式使用了贪婪匹配的.*,导致无法正确匹配源主题结构,RegexRouter SMT因此未生效:

  • 源主题为app.service-internal.events-backfilling-ids,原正则app\.(.*)\-internal\.events-backfilling-ids中,贪婪模式的.*会尽可能匹配更多字符,最终无法匹配到-internal的固定后缀部分,整个正则表达式不匹配源主题,SMT也就不会修改主题名。
  • 如果目标集群不存在与源同名的主题,Replicator就无法完成消息复制;而直接使用topic.rename.format指定目标主题时,绕过了正则匹配的问题,因此复制正常。

解决方案

修正正则表达式,确保能精准匹配到-internal前的分组内容,有两种可靠方式:

方式1:使用非贪婪匹配

将.*改为.*?,让正则匹配到第一个-internal为止:

"connector.class": "io.confluent.connect.replicator.ReplicatorSourceConnector",
"topic.whitelist": "app.service-internal.events-backfilling-ids",

"transforms": "formatName",
"transforms.formatName.type": "org.apache.kafka.connect.transforms.RegexRouter",
"transforms.formatName.regex": "app\\.(.*?)-internal\\.events-backfilling-ids",
"transforms.formatName.replacement": "app.$1.events-ingestion-ids"

方式2:使用排除字符精确匹配

用[^-]+匹配不含-的字符串(正好对应service部分),避免贪婪匹配的问题:

"connector.class": "io.confluent.connect.replicator.ReplicatorSourceConnector",
"topic.whitelist": "app.service-internal.events-backfilling-ids",

"transforms": "formatName",
"transforms.formatName.type": "org.apache.kafka.connect.transforms.RegexRouter",
"transforms.formatName.regex": "app\\.([^-]+)-internal\\.events-backfilling-ids",
"transforms.formatName.replacement": "app.$1.events-ingestion-ids"

额外注意事项

  • 不要同时混用topic.rename.format和RegexRouter SMT,若需保留topic.rename.format,需设置为"topic.rename.format": "${topic}",确保SMT能接管主题重命名逻辑。
  • 可以用正则测试工具验证表达式是否能正确匹配源主题,并确认分组$1的内容为service,避免再次出现匹配失败的情况。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.01 23:47:28