CONFLUENT PLATFORM
The following provides usage information for the Apache Kafka® SMT org.apache.kafka.connect.transforms.RegexRouter.
org.apache.kafka.connect.transforms.RegexRouter
Update the record’s topic using the configured regular expression and replacement string.
Under the hood, the regex is compiled to a java.util.regex.Pattern. If the pattern matches the input topic, java.util.regex.Matcher#replaceFirst() is used with the replacement string to obtain the new topic.
java.util.regex.Pattern
java.util.regex.Matcher#replaceFirst()
The following examples show how to configure and use RegexRouter.
RegexRouter
This configuration snippet shows how to remove the prefix soe- from the beginning of a topic.
soe-
"transforms":"dropPrefix", "transforms.dropPrefix.type":"org.apache.kafka.connect.transforms.RegexRouter", "transforms.dropPrefix.regex":"soe-(.*)", "transforms.dropPrefix.replacement":"$1"
Before: soe-Order
soe-Order
After: Order
Order
This configuration snippet shows how to add the prefix acme_ to the beginning of a topic.
acme_
"transforms"="AddPrefix" "transforms.AddPrefix.type"="org.apache.kafka.connect.transforms.RegexRouter" "transforms.AddPrefix.regex"=".*" "transforms.AddPrefix.replacement"="acme_$0"
Before: Order
After: acme_Order
acme_Order
regex
replacement
Transformations can be configured with predicates so that the transformation is applied only to records which satisfy a condition. You can use predicates in a transformation chain and, when combined with the Filter (Apache Kafka), predicates can conditionally filter out specific records. For details and examples, see Predicates.