How to change the name of the topic generated by Kafka Connect Source Connector
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Apache Kafka, a popular open-source stream-processing software platform, manages real-time data feeds with high-throughput and low-latency. Kafka Connect is a component of Apache Kafka which makes it easier to integrate Kafka with other data sources and sinks. Source connectors pull data from a data source into Kafka, while sink connectors push data from Kafka to a data destination.
Understanding Kafka Connect Source Connector Topic Naming
By default, the Kafka Connect source connector names topics based on the name of the database and table from which it is sourcing data. For instance, if data is being sourced from a table named orders in a database named sales, the default topic name might be sales.orders. However, there might be situations where a custom topic naming convention is desired, for example, to adhere to an organization's specific naming standards or to integrate seamlessly with existing systems.
How to Change Topic Names in Kafka Connect
Changing the topic names in Kafka Connect involves configuring the source connector properties. Here, the topic.prefix option is commonly used to customize how topic names are generated.
Using topic.prefix
The topic.prefix configuration allows you to specify a string that is prepended to the name of the table to form the topic name. If not specified, the default is an empty string, which implies the topic name will directly be the table name.
Example:
If you set topic.prefix to prod_, and your table name is orders, your Kafka topic will be named prod_orders.
Transformer in Kafka Connect
Another method to customize the topic name more dynamically is by using Single Message Transforms (SMTs). SMTs are used to modify the data and its metadata as it passes through Kafka Connect. This includes being able to change the topic name based on the contents of the message itself or other criteria.
Example of an SMT configuration for setting a custom topic name:
In the above example, RegexRouter is used to set every message to the same topic, my_custom_topic_name, irrespective of its original topic.
Common Issues and Considerations
- Compatibility: Ensure that the new topic names conform to any topics already consumed by other Kafka clients or systems.
- Data Consistency: Changing topic names might cause data partitioning changes. Be mindful of data ordering and consistency requirements.
- Monitoring: Adjust monitoring tools and dashboards to reflect the new topic names.
- Consumer Configuration: Make sure all Kafka consumers are configured to listen to the new topic names.
Summary Table
| Configuration | Description | Example |
topic.prefix | A prefix added to the table name to form the topic name. | topic.prefix=prod_ results in topics like prod_orders |
transforms | Use of SMTs to dynamically alter the topic name. | transforms.changeTopic.type=org.apache.kafka.connect.transforms.RegexRouter |
| Impact | Changes how consumers and monitoring systems interact with topics. | Monitoring configurations need update. |
Best Practices and Recommendations
- Testing: Always test configuration changes in a staging environment before deploying to production.
- Documentation: Maintain thorough documentation of any changes to topic configurations to avoid confusion.
- Consistency: Keep topic naming conventions consistent across the environment to simplify management and troubleshooting.
By understanding and utilizing the configuration options available in Kafka Connect, organizations can tailor topic naming to meet their specific needs, improving integration and management of streaming data.

