Kafka Connect Transformations-RegexRouter替换主题名称为小写

时间:2020-03-24 10:38:49

标签: apache-kafka apache-kafka-connect debezium

我们正在尝试在Kafka Connect中设置连接器(Debezium),并通过正则表达式转换此连接器生成的所有主题名称。下面的正则表达式可以正常工作并检测到我们想要的模式,但是我们还需要以小写形式创建所有主题名称。

我们尝试将其放在替换表达式中为 \ L $ 1 ,但这只是在主题名称前打印和L ,例如 LOutbound.Policy 而不是 outbound.policy

有人知道该怎么做吗?预先感谢!

这是连接器curl命令

curl -i -X PUT http://kafka-alpha-cp-kafka-connect:8083/connectors/kafka-bi-datacontract/config -H "Content-Type: application/json" -d '{
"name": "kafka-bi-datacontract",
"connector.class" : "io.debezium.connector.sqlserver.SqlServerConnector",
"database.hostname" : "ukdb3232123",
"database.server.name" : "ukdb3232123\\perf",
"database.port" : "12442",
"database.user" : "KafkaConnect-BI",
"database.password" : "*******",
"database.dbname" : "BeazleyIntelligenceDataContract",
"snapshot.lock.timeout.ms" : "10000000",
"table.whitelist" : "Outbound.Policy,Outbound.Section",
"database.history.kafka.bootstrap.servers" : "kafka-alpha-cp-kafka-headless:9092",
"database.history.kafka.topic": "schema-changes.bidatacontract",
"transforms": "dropTopicPrefix",
"transforms.dropTopicPrefix.type":"org.apache.kafka.connect.transforms.RegexRouter",
"transforms.dropTopicPrefix.regex":"^[^.]+.(.*)",
"transforms.dropTopicPrefix.replacement":"\\L$1"
}'

1 个答案:

答案 0 :(得分:1)

\L$1\\L$1L$1相同。

您需要创建/查找自己的变换以降低外壳大小。

完成后,您可以执行以下操作

"transforms": "dropTopicPrefix,lowertopic",

"transforms.dropTopicPrefix.type":"org.apache.kafka.connect.transforms.RegexRouter",
"transforms.dropTopicPrefix.regex":"^[^.]+.(.*)",
"transforms.dropTopicPrefix.replacement":"$1",

"transforms.lowerTopic.type":"com.example.foo.LowerCase$Topic",